📄 rendererutils.java
字号:
} } Object value = ((ValueHolder)component).getValue(); Converter converter = ((ValueHolder)component).getConverter(); if (converter == null && value != null) { if (value instanceof String) { return (String) value; } try { converter = facesContext.getApplication().createConverter(value.getClass()); } catch (FacesException e) { log.error("No converter for class " + value.getClass().getName() + " found (component id=" + component.getId() + ")."); // converter stays null } } if (converter == null) { if (value == null) { return ""; } else { return value.toString(); } } else { return converter.getAsString(facesContext, component, value); } } catch(PropertyNotFoundException ex) { log.error("Property not found - called by component : "+getPathToComponent(component)); throw ex; } } /** * See JSF Spec. 8.5 Table 8-1 * @param value * @return */ public static boolean isDefaultAttributeValue(Object value) { if (value == null) { return true; } else if (value instanceof Boolean) { return ((Boolean)value).booleanValue() == false; } else if (value instanceof Number) { if (value instanceof Integer) { return ((Number)value).intValue() == Integer.MIN_VALUE; } else if (value instanceof Double) { return ((Number)value).doubleValue() == Double.MIN_VALUE; } else if (value instanceof Long) { return ((Number)value).longValue() == Long.MIN_VALUE; } else if (value instanceof Byte) { return ((Number)value).byteValue() == Byte.MIN_VALUE; } else if (value instanceof Float) { return ((Number)value).floatValue() == Float.MIN_VALUE; } else if (value instanceof Short) { return ((Number)value).shortValue() == Short.MIN_VALUE; } } return false; } /** * Find the proper Converter for the given UIOutput component. * @return the Converter or null if no Converter specified or needed * @throws FacesException if the Converter could not be created */ public static Converter findUIOutputConverter(FacesContext facesContext, UIOutput component) throws FacesException { return _SharedRendererUtils.findUIOutputConverter(facesContext, component); } /** * Find proper Converter for the entries in the associated List or Array of * the given UISelectMany as specified in API Doc of UISelectMany. * @return the Converter or null if no Converter specified or needed * @throws FacesException if the Converter could not be created */ public static Converter findUISelectManyConverter(FacesContext facesContext, UISelectMany component) { Converter converter = component.getConverter(); if (converter != null) return converter; //Try to find out by value binding ValueBinding vb = component.getValueBinding("value"); if (vb == null) return null; Class valueType = vb.getType(facesContext); if (valueType == null) return null; if (List.class.isAssignableFrom(valueType)) { //According to API Doc of UISelectMany the assumed entry type for a List is String //--> no converter needed return null; } if (!valueType.isArray()) { throw new IllegalArgumentException("ValueBinding for UISelectMany : "+getPathToComponent(component)+" must be of type List or Array"); } Class arrayComponentType = valueType.getComponentType(); if (String.class.equals(arrayComponentType)) return null; //No converter needed for String type if (Object.class.equals(arrayComponentType)) return null; //There is no converter for Object class try { return facesContext.getApplication().createConverter(arrayComponentType); } catch (FacesException e) { log.error("No Converter for type " + arrayComponentType.getName() + " found", e); return null; } } public static void checkParamValidity(FacesContext facesContext, UIComponent uiComponent, Class compClass) { if(facesContext == null) throw new NullPointerException("facesContext may not be null"); if(uiComponent == null) throw new NullPointerException("uiComponent may not be null"); //if (compClass != null && !(compClass.isAssignableFrom(uiComponent.getClass()))) // why isAssignableFrom with additional getClass method call if isInstance does the same? if (compClass != null && !(compClass.isInstance(uiComponent))) { throw new IllegalArgumentException("uiComponent : "+getPathToComponent(uiComponent)+ " is not instance of "+compClass.getName()+" as it should be"); } } public static void renderChildren(FacesContext facesContext, UIComponent component) throws IOException { if (component.getChildCount() > 0) { for (Iterator it = component.getChildren().iterator(); it.hasNext(); ) { UIComponent child = (UIComponent)it.next(); renderChild(facesContext, child); } } } public static void renderChild(FacesContext facesContext, UIComponent child) throws IOException { if (!child.isRendered()) { return; } child.encodeBegin(facesContext); if (child.getRendersChildren()) { child.encodeChildren(facesContext); } else { renderChildren(facesContext, child); } child.encodeEnd(facesContext); } /** * @param uiSelectOne * @return List of SelectItem Objects */ public static List getSelectItemList(UISelectOne uiSelectOne) { return internalGetSelectItemList(uiSelectOne); } /** * @param uiSelectMany * @return List of SelectItem Objects */ public static List getSelectItemList(UISelectMany uiSelectMany) { return internalGetSelectItemList(uiSelectMany); } private static List internalGetSelectItemList(UIComponent uiComponent) { /* TODO: Shall we cache the list in a component attribute? ArrayList list = (ArrayList)uiComponent.getAttributes().get(SELECT_ITEM_LIST_ATTR); if (list != null) { return list; } */ List list = new ArrayList(uiComponent.getChildCount()); for (Iterator children = uiComponent.getChildren().iterator(); children.hasNext(); ) { UIComponent child = (UIComponent)children.next(); if (child instanceof UISelectItem) { Object value = ((UISelectItem) child).getValue(); if (value != null) { //get SelectItem from model via value binding if (!(value instanceof SelectItem)) { ValueBinding binding = ((UISelectItem) child).getValueBinding("value"); throw new IllegalArgumentException("Value binding '"+(binding==null?null:binding.getExpressionString()) +"' of UISelectItem : " + getPathToComponent(child) + " does not reference an Object of type SelectItem"); } list.add(value); } else { Object itemValue = ((UISelectItem)child).getItemValue(); String label = ((UISelectItem)child).getItemLabel(); String description = ((UISelectItem)child).getItemDescription(); boolean disabled = ((UISelectItem)child).isItemDisabled(); if (label == null) { list.add(new SelectItem(itemValue, itemValue.toString(), description, disabled)); } else { list.add(new SelectItem(itemValue, label, description, disabled)); } } } else if (child instanceof UISelectItems) { UISelectItems items = ((UISelectItems) child); Object value = items.getValue(); // TODO : Check here for getSubmittedValue. if (value instanceof SelectItem) { list.add(value); } else if (value instanceof SelectItem[]) { for (int i = 0; i < ((SelectItem[])value).length; i++) { list.add(((SelectItem[])value)[i]); } } else if (value instanceof Collection) { for (Iterator it = ((Collection)value).iterator(); it.hasNext();) { Object item = it.next(); if (!(item instanceof SelectItem)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -