/** * Algorithm works as follows; - If it's an input component, submitted value is checked first * since it'd be the value to be used in case validation errors terminates jsf lifecycle - Finally * the value of the component is retrieved from backing bean and if there's a converter, converted * value is returned * * <p>- If the component is not a value holder, toString of component is used to support Facelets * UIInstructions. * * @param facesContext FacesContext instance * @param component UIComponent instance whose value will be returned * @return End text */ public static String getStringValueToRender(FacesContext facesContext, UIComponent component) { if (component instanceof ValueHolder) { if (component instanceof EditableValueHolder) { Object submittedValue = ((EditableValueHolder) component).getSubmittedValue(); if (submittedValue != null) { return submittedValue.toString(); } } ValueHolder valueHolder = (ValueHolder) component; Object value = valueHolder.getValue(); if (value == null) return ""; // first ask the converter if (valueHolder.getConverter() != null) { return valueHolder.getConverter().getAsString(facesContext, component, value); } // Try to guess else { ValueExpression expr = component.getValueExpression("value"); if (expr != null) { Class<?> valueType = expr.getType(facesContext.getELContext()); if (valueType != null) { Converter converterForType = facesContext.getApplication().createConverter(valueType); if (converterForType != null) return converterForType.getAsString(facesContext, component, value); } } } // No converter found just return the value as string return value.toString(); } else { // This would get the plain texts on UIInstructions when using Facelets String value = component.toString(); if (value != null) return value.trim(); else return ""; } }
Object getValue() { Map<UIData, Integer> savedRowIndexes = new HashMap<UIData, Integer>(); // save current row and set row needed to get value for (Iterator<UIData> i = reverse(uiDataRowMap.keySet().iterator()); i.hasNext(); ) { UIData uiData = i.next(); savedRowIndexes.put(uiData, uiData.getRowIndex()); uiData.setRowIndex(uiDataRowMap.get(uiData)); } Object value = component.getValue(); // restore rows for (Iterator<UIData> i = reverse(savedRowIndexes.keySet().iterator()); i.hasNext(); ) { UIData uiData = i.next(); uiData.setRowIndex(savedRowIndexes.get(uiData)); } return value; }