Example usage for javax.el ExpressionFactory createValueExpression

List of usage examples for javax.el ExpressionFactory createValueExpression

Introduction

In this page you can find the example usage for javax.el ExpressionFactory createValueExpression.

Prototype

public abstract ValueExpression createValueExpression(ELContext context, String expression,
        Class<?> expectedType);

Source Link

Document

Create a new value expression.

Usage

From source file:com.thruzero.common.jsf.utils.FacesUtils.java

private static Object getExpressionValue(String el, Class<?> cls) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
    ValueExpression valueExpression = expressionFactory.createValueExpression(facesContext.getELContext(), el,
            cls);/*from  ww  w . j a v  a 2  s .  com*/

    Object result = valueExpression.getValue(facesContext.getELContext());

    return result;
}

From source file:AIR.Common.Web.taglib.JsfHelpers.java

public static void setValueExpressions(UIComponent component, Map<String, String> valueExpressions,
        FacesContext context) {//from  w  ww  .  j  a  v  a  2  s.  c  o  m
    if (valueExpressions == null || valueExpressions.size() == 0)
        return;
    if (context == null) {
        context = FacesContext.getCurrentInstance();
    }

    Application application = context.getApplication();
    // http://stackoverflow.com/a/16058002/1961102
    if (valueExpressions != null && !valueExpressions.isEmpty()) {
        ExpressionFactory factory = application.getExpressionFactory();
        ELContext ctx = context.getELContext();
        for (Map.Entry<String, String> entry : valueExpressions.entrySet()) {
            ValueExpression expr = factory.createValueExpression(ctx, entry.getValue(), Object.class);
            component.setValueExpression(entry.getKey(), expr);
        }
    }
}

From source file:de.beyondjava.angularFaces.core.ELTools.java

public static ValueExpression createValueExpression(String p_expression) {
    FacesContext context = FacesContext.getCurrentInstance();
    ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory();
    ELContext elContext = context.getELContext();
    ValueExpression vex = expressionFactory.createValueExpression(elContext, p_expression, Object.class);
    return vex;/*from ww w .j av a  2  s .  co  m*/
}

From source file:de.beyondjava.angularFaces.core.ELTools.java

/**
 * Evaluates an EL expression into an object.
 *
 * @param p_expression/*  w  w  w .  ja v a2s  .  c  o  m*/
 * @return
 */
public static Object evalAsObject(String p_expression) {
    FacesContext context = FacesContext.getCurrentInstance();
    ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory();
    ELContext elContext = context.getELContext();
    ValueExpression vex = expressionFactory.createValueExpression(elContext, p_expression, Object.class);
    Object result = vex.getValue(elContext);
    return result;
}

From source file:de.beyondjava.angularFaces.core.ELTools.java

/**
 * Evaluates an EL expression into a string.
 *
 * @param p_expression/*  w w  w.  j  a va 2s . c om*/
 * @return
 */
public static String evalAsString(String p_expression) {
    FacesContext context = FacesContext.getCurrentInstance();
    ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory();
    ELContext elContext = context.getELContext();
    ValueExpression vex = expressionFactory.createValueExpression(elContext, p_expression, String.class);
    String result = (String) vex.getValue(elContext);
    return result;
}

From source file:com.googlecode.jsfFlex.taglib.AbstractFlexUIComponentTagBase.java

protected void setBooleanProperty(FacesContext context, UIComponent component, String propName, String value) {

    if (value != null) {
        ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory();
        ValueExpression ve = expressionFactory.createValueExpression(context.getELContext(), value,
                Object.class);
        if (ve != null) {
            component.setValueExpression(propName, ve);
        } else {/*from  w ww . j av a 2  s.  c o m*/
            component.getAttributes().put(propName, Boolean.valueOf(value));
        }
    }
}

From source file:com.googlecode.jsfFlex.taglib.AbstractFlexUIComponentTagBase.java

protected void setIntegerProperty(FacesContext context, UIComponent component, String propName, String value) {

    if (value != null) {
        ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory();
        ValueExpression ve = expressionFactory.createValueExpression(context.getELContext(), value,
                Object.class);
        if (ve != null) {
            component.setValueExpression(propName, ve);
        } else {/*ww  w  . ja v  a 2 s .  co  m*/
            component.getAttributes().put(propName, Integer.valueOf(value));
        }
    }
}

From source file:com.googlecode.jsfFlex.taglib.AbstractFlexUIComponentTagBase.java

protected void setLongProperty(FacesContext context, UIComponent component, String propName, String value) {

    if (value != null) {
        ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory();
        ValueExpression ve = expressionFactory.createValueExpression(context.getELContext(), value,
                Object.class);
        if (ve != null) {
            component.setValueExpression(propName, ve);
        } else {//w  ww  .  j a va 2s  .  c o m
            component.getAttributes().put(propName, Long.valueOf(value));
        }
    }
}

From source file:com.googlecode.jsfFlex.taglib.AbstractFlexUIComponentTagBase.java

protected void setStringProperty(FacesContext context, UIComponent component, String propName, String value) {

    if (value != null) {
        ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory();
        ValueExpression ve = expressionFactory.createValueExpression(context.getELContext(), value,
                Object.class);
        if (ve != null) {
            component.setValueExpression(propName, ve);
        } else {/*from w  ww  . j  a v a  2  s.  com*/
            component.getAttributes().put(propName, value);
        }
    }
}

From source file:de.openknowledge.extensions.jsf.model.ModelMethod.java

@Override
public void updateModel(FacesContext context) {
    ValueExpression expression = getValueExpression("value");
    SimpleMethodExpressionParser parser = new SimpleMethodExpressionParser(expression.getExpressionString());
    SimpleMethodExpression methodExpression = parser.parse();
    ExpressionFactory expressionFactory = notNull(context, "context may not be null").getApplication()
            .getExpressionFactory();/*from   w ww .j a  v  a2s  .c o  m*/
    ValueExpression baseExpression = expressionFactory.createValueExpression(context.getELContext(),
            "#{" + methodExpression.getBase() + '}', Object.class);
    Object baseValue = baseExpression.getValue(context.getELContext());
    Class<? extends Object> baseType = baseValue.getClass();
    UIInput[] parameterComponents = findComponents(methodExpression);
    Class<?>[] parameterTypes = findParameterTypes(context, methodExpression, expressionFactory,
            parameterComponents);
    Method method = findMethod(baseType, methodExpression.getMethodName(), parameterTypes);
    Object[] parameters = findParameters(context, methodExpression, expressionFactory, parameterComponents,
            parameterTypes);
    try {
        method.invoke(baseValue, parameters);
    } catch (InvocationTargetException e) {
        throw new ELException(e.getTargetException());
    } catch (Exception e) {
        throw new ELException(e);
    }
}