Java Code Examples for javax.faces.component.UIComponent#getValueExpression()
The following examples show how to use
javax.faces.component.UIComponent#getValueExpression() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EnumConverter.java From development with Apache License 2.0 | 7 votes |
public Object getAsObject(FacesContext context, UIComponent component, String value) { if (value == null || component.getValueExpression("value") == null) { return null; } @SuppressWarnings("unchecked") Class<? extends Enum<?>> enumType = (Class<? extends Enum<?>>) component .getValueExpression("value").getType(context.getELContext()); for (Enum<?> e : enumType.getEnumConstants()) { if (e.toString().equals(value)) { return e; } } return null; }
Example 2
Source File: ELTools.java From BootsFaces-OSP with Apache License 2.0 | 7 votes |
/** * Return the core value expression of a specified component * * @param component * @return */ public static String getCoreValueExpression(UIComponent component) { ValueExpression valueExpression = component.getValueExpression("value"); if (null != valueExpression) { String v = valueExpression.getExpressionString(); if (null != v) { Matcher matcher = EL_EXPRESSION.matcher(v); if (matcher.find()) { String exp = matcher.group(); return exp.substring(2, exp.length() - 1); } return v; } } return null; }
Example 3
Source File: CoreRenderer.java From BootsFaces-OSP with Apache License 2.0 | 6 votes |
protected Converter resolveConverter(FacesContext context, UIComponent c, Object value) { if (!(c instanceof ValueHolder)) { return null; } Converter cnv = ((ValueHolder) c).getConverter(); if (cnv != null) { return cnv; } else { ValueExpression ve = c.getValueExpression("value"); if (ve != null) { Class<?> valType = ve.getType(context.getELContext()); if (valType != null && (!valType.isPrimitive())) { // workaround for a Mojarra bug (#966) return context.getApplication().createConverter(valType); } else if (valType != null && (value instanceof String)) { // workaround for the workaround of the Mojarra bug (#977) return context.getApplication().createConverter(valType); } } return null; } }
Example 4
Source File: SketchPadRenderer.java From ctsms with GNU Lesser General Public License v2.1 | 5 votes |
private Converter getConverter(FacesContext context, UIComponent component) { Converter converter = ((UIInput) component).getConverter(); if (converter != null) { return converter; } ValueExpression exp = component.getValueExpression("value"); if (exp == null) { return null; } Class valueType = exp.getType(context.getELContext()); if (valueType == null) { return null; } return context.getApplication().createConverter(valueType); }
Example 5
Source File: BsfUtils.java From BootsFaces-OSP with Apache License 2.0 | 5 votes |
/** * <p> * Returns the <code>label</code> property from the specified component. * </p> * Simplified and adapted version of the implementation of Mojarra 2.2.8-b02 * (see MessageFactory). * * @param context * - the <code>FacesContext</code> for the current request * * @return the label, if any, of the component */ public static String getLabel(FacesContext context, UIComponent comp) { Object o = comp.getAttributes().get("label"); if (o == null || (o instanceof String && ((String) o).length() == 0)) { ValueExpression vex = comp.getValueExpression("label"); if (null != vex) return (String) vex.getValue(context.getELContext()); } if (o == null) { // Use the "clientId" if there was no label specified. o = comp.getClientId(context); } return (String) o; }
Example 6
Source File: ELTools.java From BootsFaces-OSP with Apache License 2.0 | 5 votes |
/** * Yields the type of the variable displayed by a component. * * @param p_component * the UIComponent * @return the type (as class) */ public static Class<?> getType(UIComponent p_component) { ValueExpression valueExpression = p_component.getValueExpression("value"); if (valueExpression != null) { FacesContext context = FacesContext.getCurrentInstance(); ELContext elContext = context.getELContext(); return valueExpression.getType(elContext); } return null; }
Example 7
Source File: ELTools.java From BootsFaces-OSP with Apache License 2.0 | 5 votes |
/** * Which annotations are given to an object displayed by a JSF component? * * @param p_component * the component * @return null if there are no annotations, or if they cannot be accessed */ public static Annotation[] readAnnotations(UIComponent p_component) { ValueExpression valueExpression = p_component.getValueExpression("value"); if (valueExpression != null && valueExpression.getExpressionString() != null && valueExpression.getExpressionString().length()>0) { return readAnnotations(valueExpression, p_component); } return null; }
Example 8
Source File: SelectOneMenuRenderer.java From BootsFaces-OSP with Apache License 2.0 | 5 votes |
private Converter findImplicitConverter(FacesContext context, UIComponent component) { ValueExpression ve = component.getValueExpression("value"); if (ve != null) { Class<?> valueType = ve.getType(context.getELContext()); if (valueType != null) return context.getApplication().createConverter(valueType); } return null; }
Example 9
Source File: ValueExpressionHelper.java From BootsFaces-OSP with Apache License 2.0 | 5 votes |
/** * Source adapted from Seam's enumConverter. The goal is to get the type to which this component's value is bound. * First, check if the valueExpression provides the type. For dropdown-like components, this may not work, so check * for SelectItems children. * * @param context the current FacesContext * @param uiComponent * @param validTypes a list of types to look for * @return null if a valid type cannot be found */ public static Class<?> getValueType(FacesContext context, UIComponent uiComponent, Collection<Class<?>> validTypes) { Class<?> valueType = getValueType(context, uiComponent); if (valueType != null && isValid(validTypes, valueType)) { return valueType; } else { for (UIComponent child : uiComponent.getChildren()) { UIComponent c = (UIComponent) child; ValueExpression expr = c.getValueExpression("value"); Object val = expr == null ? null : expr.getValue(context.getELContext()); if (val != null) { valueType = val.getClass(); if (valueType.isArray() && isValid(validTypes, valueType.getComponentType())) { return valueType; } else if (val instanceof Collection<?>) { valueType = ((Collection<?>) val).iterator().next().getClass(); if (isValid(validTypes, valueType)) { return valueType; } } } } } return null; }
Example 10
Source File: ELTools.java From BootsFaces-OSP with Apache License 2.0 | 4 votes |
public static boolean hasValueExpression(UIComponent component) { ValueExpression valueExpression = component.getValueExpression("value"); return null != valueExpression; }
Example 11
Source File: CoreRenderer.java From BootsFaces-OSP with Apache License 2.0 | 3 votes |
/** * Returns type of the provided attribute name's {@link ValueExpression} of the provided component. * * @param component Component to get attribute type for. * @param attribute Attribute to get type for. * * @return Type of the provided attribute name's {@link ValueExpression} of the provided component. */ public static Class<?> getAttributeType(UIComponent component, String attribute) { ValueExpression valueExpression = component.getValueExpression(attribute); return valueExpression == null ? null : valueExpression.getType(FacesContext.getCurrentInstance().getELContext()); }
Example 12
Source File: ValueExpressionHelper.java From BootsFaces-OSP with Apache License 2.0 | 2 votes |
/** * return the type for the "value" attribute of the given component, if it exists. Return null otherwise. * @param context * @param comp * @return */ public static Class<?> getValueType(FacesContext context, UIComponent comp) { ValueExpression expr = comp.getValueExpression("value"); Class<?> valueType = expr == null ? null : expr.getType(context.getELContext()); return valueType; }