Java Code Examples for javax.el.ValueExpression#getType()

The following examples show how to use javax.el.ValueExpression#getType() . 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: AstIdentifier.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public Class<?> getType(EvaluationContext ctx) throws ELException {
    VariableMapper varMapper = ctx.getVariableMapper();
    if (varMapper != null) {
        ValueExpression expr = varMapper.resolveVariable(this.image);
        if (expr != null) {
            return expr.getType(ctx.getELContext());
        }
    }
    ctx.setPropertyResolved(false);
    Class<?> result = ctx.getELResolver().getType(ctx, null, this.image);
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled.null", this.image));
    }
    return result;
}
 
Example 2
Source File: AstIdentifier.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public Class<?> getType(EvaluationContext ctx) throws ELException {
    VariableMapper varMapper = ctx.getVariableMapper();
    if (varMapper != null) {
        ValueExpression expr = varMapper.resolveVariable(this.image);
        if (expr != null) {
            return expr.getType(ctx.getELContext());
        }
    }
    ctx.setPropertyResolved(false);
    Class<?> result = ctx.getELResolver().getType(ctx, null, this.image);
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled.null", this.image));
    }
    return result;
}
 
Example 3
Source File: AstIdentifier.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public Class<?> getType(EvaluationContext ctx) throws ELException {
    VariableMapper varMapper = ctx.getVariableMapper();
    if (varMapper != null) {
        ValueExpression expr = varMapper.resolveVariable(this.image);
        if (expr != null) {
            return expr.getType(ctx.getELContext());
        }
    }
    ctx.setPropertyResolved(false);
    Class<?> result = ctx.getELResolver().getType(ctx, null, this.image);
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled.null", this.image));
    }
    return result;
}
 
Example 4
Source File: CoreRenderer.java    From BootsFaces-OSP with Apache License 2.0 6 votes vote down vote up
/**
 * Finds the appropriate converter for a given value holder
 *
 * @param fc
 *            FacesContext instance
 * @param vh
 *            ValueHolder instance to look converter for
 * @return Converter
 */
public static Converter getConverter(FacesContext fc, ValueHolder vh) {
	// explicit converter
	Converter converter = vh.getConverter();

	// try to find implicit converter
	if (converter == null) {
		ValueExpression expr = ((UIComponent) vh).getValueExpression("value");
		if (expr != null) {
			Class<?> valueType = expr.getType(fc.getELContext());
			if (valueType != null) {
				converter = fc.getApplication().createConverter(valueType);
			}
		}
	}

	return converter;
}
 
Example 5
Source File: CoreRenderer.java    From BootsFaces-OSP with Apache License 2.0 6 votes vote down vote up
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 6
Source File: RuleEvaluator.java    From proctor with Apache License 2.0 6 votes vote down vote up
/**
 * @throws IllegalArgumentException if type of expression is not boolean
 */
static void checkRuleIsBooleanType(final String rule, final ELContext elContext, final ValueExpression ve) {
    // apache-el is an expression language, not a rule language, and it is very lenient
    // sadly that means it will just evaluate to false when users make certain mistakes, e.g. by
    // coercing String value "xyz" to boolean false, instead of throwing an exception.
    // To support users writing rules, be more strict here in requiring the type of the
    // value to be expected before coercion
    Class<?> type = ve.getType(elContext);
    if (ClassUtils.isPrimitiveWrapper(type)) {
        type = ClassUtils.wrapperToPrimitive(type);
    }
    // allow null to be coerced for historic reasons
    if ((type != null) && (type != boolean.class)) {
        throw new IllegalArgumentException("Received non-boolean return value: " + type + " from rule " + rule);
    }
}
 
Example 7
Source File: SketchPadRenderer.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 8
Source File: ELTools.java    From BootsFaces-OSP with Apache License 2.0 5 votes vote down vote up
/**
 * 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 9
Source File: SelectOneMenuRenderer.java    From BootsFaces-OSP with Apache License 2.0 5 votes vote down vote up
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 10
Source File: CoreRenderer.java    From BootsFaces-OSP with Apache License 2.0 3 votes vote down vote up
/**
 * 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 11
Source File: ValueExpressionHelper.java    From BootsFaces-OSP with Apache License 2.0 2 votes vote down vote up
/**
 * 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;
}