Example usage for javax.el ValueExpression getValue

List of usage examples for javax.el ValueExpression getValue

Introduction

In this page you can find the example usage for javax.el ValueExpression getValue.

Prototype

public abstract Object getValue(ELContext context);

Source Link

Usage

From source file:eu.eubrazilcc.lvl.storage.security.el.PermissionElBuilder.java

/**
 * Builds a permission expression from a template compatible with EL (expression language). The following are valid examples of
 * permission templates which includes at least one property from {@link User}, considering the userid <tt>username</tt> and 
 * the provider <tt>lvl</tt>:
 * <ul>/*from   ww w. j  a  v a  2  s . co  m*/
 * <li><tt>level1:${user.userid}:level3</tt> - builds to: <tt>level1:username:level3</tt></li>
 * <li><tt>level1:${user.userid}@${user.provider}</tt> - builds to: <tt>level1:username@lvl</tt></li>
 * <li><tt>${user.userid}:${user.userid}@${user.provider}</tt> - <tt>username:username@lvl</tt></li>
 * </ul>
 * @param template - permission template to be parsed and completed with user details
 * @param user - contains the details of the user
 * @return A permission expression where the EL parameters are replaced by the corresponding properties from the specified user.
 */
public static String buildPermission(final String template, final User user) {
    checkNotNull(template, "Uninitialized or invalid permission template");
    checkArgument(user != null && isNotBlank(user.getUserid()) && isNotBlank(user.getProvider()),
            "Uninitialized or invalid user");
    final PermissionElContext ctxt = PermissionElContext.builder().user(user).build();
    final String template2 = template.trim();
    final ValueExpression expr = EXPR_FACTORY.createValueExpression(ctxt, template2, String.class);
    return expr.getValue(ctxt).toString();
}

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 w  w w .  j  a v  a 2s. c o  m

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

    return result;
}

From source file:org.nuxeo.ecm.platform.ui.web.util.ComponentTagUtils.java

/**
 * Resolves an expression from a given facelet context, using its {@link ExpressionFactory} that can hold a wider
 * context than the faces context behind it.
 * <p>/*from   w  ww.j a v  a  2 s.c  o  m*/
 * Resolves the expression a second time when first resolution gives a String value using the EL Expression syntax.
 * <p>
 * Does not throw any error when resolution fails (only logs an error message).
 */
public static Object resolveElExpression(FaceletContext faceletContext, String elExpression) {
    if (!isValueReference(elExpression)) {
        // literal
        return elExpression;
    } else {
        if (faceletContext == null) {
            log.error("FaceletContext is null => cannot resolve el expression '" + elExpression + "'");
            return null;
        }
        // expression => evaluate
        ExpressionFactory eFactory = faceletContext.getExpressionFactory();
        ELContext elContext = faceletContext.getFacesContext().getELContext();
        ValueExpression expr = eFactory.createValueExpression(faceletContext, elExpression, Object.class);
        try {
            return expr.getValue(elContext);
        } catch (ELException e) {
            log.error("Facelet context: Error processing expression '" + elExpression + "'", e);
            return null;
        }
    }
}

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

/**
 * Evaluates an EL expression into an object.
 *
 * @param p_expression/*from www .  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:net.vpc.common.jsf.FacesUtils.java

public static Object evaluateEL(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);
    return vex.getValue(elContext);
}

From source file:ec.edu.chyc.manejopersonal.managebean.GestorAcuerdoConfidencialidad.java

public static GestorAcuerdoConfidencialidad getInstance() {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ELContext context = facesContext.getELContext();
    ValueExpression ex = facesContext.getApplication().getExpressionFactory().createValueExpression(context,
            "#{gestorAcuerdoConfidencialidad}", GestorAcuerdoConfidencialidad.class);
    return (GestorAcuerdoConfidencialidad) ex.getValue(context);
}

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

/**
 * Evaluates an EL expression into a string.
 *
 * @param p_expression//www  . j  a  v  a 2  s .  c  o m
 * @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:ec.edu.chyc.manejopersonal.managebean.GestorContrato.java

public static GestorContrato getInstance() {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ELContext context = facesContext.getELContext();
    ValueExpression ex = facesContext.getApplication().getExpressionFactory().createValueExpression(context,
            "#{gestorContrato}", GestorContrato.class);
    return (GestorContrato) ex.getValue(context);
}

From source file:ec.edu.chyc.manejopersonal.managebean.GestorConvenio.java

public static GestorConvenio getInstance() {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ELContext context = facesContext.getELContext();
    ValueExpression ex = facesContext.getApplication().getExpressionFactory().createValueExpression(context,
            "#{gestorConvenio}", GestorConvenio.class);
    return (GestorConvenio) ex.getValue(context);
}

From source file:org.n52.geolabel.component.GeoLabelComponent.java

/**
 * Marks a specific GEO label service for the current request as broken.
 * Important to not send any further GeoLabel requests in case of an error.
 * /*  w  w  w . j a v  a  2s.  c  o  m*/
 * @param context
 */
private static void setServiceFailed(String endpoint, FacesContext context) {
    ValueExpression expression = context.getApplication().getExpressionFactory().createValueExpression(
            context.getELContext(), "#{geoLabelResourcesBean}", GeoLabelResourcesBean.class);
    GeoLabelResourcesBean resourcesBean = (GeoLabelResourcesBean) expression.getValue(context.getELContext());
    resourcesBean.setGeoLabelServiceFailed(endpoint);
}