示例#1
0
  private String encodeParentAndChildrenAsString(FacesContext fc, UIComponent uic) {
    StringBuffer str = new StringBuffer();
    if (uic instanceof CommandSortHeader) {
      if (uic.getChildCount() > 0) {
        Iterator iter = uic.getChildren().iterator();
        while (iter.hasNext()) {
          UIComponent child = (UIComponent) iter.next();
          str.append(encodeParentAndChildrenAsString(fc, child));
        }
      }
    }
    Object value = uic.getAttributes().get("value");
    if (value == null) {
      ValueBinding vb = uic.getValueBinding("value");
      if (vb != null) {
        value = vb.getValue(fc);
      }
    }
    if (value == null) {
      return str.toString();
    }
    Converter converter = null;
    if (uic instanceof ValueHolder) {
      converter = ((ValueHolder) uic).getConverter();
    }
    if (converter == null) {
      converter =
          FacesContext.getCurrentInstance().getApplication().createConverter(value.getClass());
    }
    if (converter != null) {
      str.append(converter.getAsString(FacesContext.getCurrentInstance(), uic, value));
    } else {
      str.append(value);
    }

    // don't process selectItems or f:param for uiCommand)
    if (uic instanceof UISelectBoolean
        || uic instanceof UISelectMany
        || uic instanceof UISelectOne
        || uic instanceof UICommand) {
      return str.toString();
    }

    if (uic.getChildCount() > 0) {
      Iterator iter = uic.getChildren().iterator();
      while (iter.hasNext()) {
        UIComponent child = (UIComponent) iter.next();
        str.append(encodeParentAndChildrenAsString(fc, child));
      }
    }
    return str.toString();
  }