Search in sources :

Example 36 with ELContext

use of javax.el.ELContext in project ofbiz-framework by apache.

the class UelUtil method setValue.

/**
 * Evaluates a Unified Expression Language expression and sets the resulting object
 * to the specified value.
 * @param context Evaluation context (variables)
 * @param expression UEL expression
 * @param expectedType The expected object Class to set
 */
public static void setValue(Map<String, Object> context, String expression, Class expectedType, Object value) {
    if (Debug.verboseOn()) {
        Debug.logVerbose("UelUtil.setValue invoked, expression = " + expression + ", value = " + value, module);
    }
    ELContext elContext = new BasicContext(context);
    ValueExpression ve = exprFactory.createValueExpression(elContext, expression, expectedType);
    ve.setValue(elContext, value);
}
Also used : ELContext(javax.el.ELContext) ValueExpression(javax.el.ValueExpression)

Example 37 with ELContext

use of javax.el.ELContext in project core by weld.

the class ELResolverTest method testErrorMessageGood.

@Test(expected = OrderException.class)
public // WELD-782
void testErrorMessageGood(BeanManagerImpl beanManager) {
    ELContext ctx = EL.createELContext(beanManager);
    EL.EXPRESSION_FACTORY.createValueExpression(ctx, "#{orderBean.orderId}", Object.class).getValue(ctx);
}
Also used : ELContext(javax.el.ELContext) Test(org.junit.Test)

Example 38 with ELContext

use of javax.el.ELContext in project core by weld.

the class ELResolverTest method testResolveBeanPropertyOfNamedBean.

/**
 * Test that the WeldELResolver only works to resolve the base of an EL
 * expression, in this case a named bean. Once the base is resolved, the
 * remainder of the expression should be delegated to the standard chain of
 * property resolvers. If the WeldELResolver oversteps its bounds by
 * trying to resolve the property against the Weld namespace, the test
 * will fail.
 */
@Test
public void testResolveBeanPropertyOfNamedBean() {
    ELContext elContext = EL.createELContext(beanManager);
    ExpressionFactory exprFactory = EL.EXPRESSION_FACTORY;
    Object value = exprFactory.createValueExpression(elContext, "#{beer.style}", String.class).getValue(elContext);
    Assert.assertEquals("Belgium Strong Dark Ale", value);
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) Test(org.junit.Test)

Example 39 with ELContext

use of javax.el.ELContext in project core by weld.

the class ELResolverTest method testResolveNormalScopedBean.

// WELD-874
@Test
public void testResolveNormalScopedBean() {
    ELContext elContext = EL.createELContext(beanManager);
    ExpressionFactory exprFactory = EL.EXPRESSION_FACTORY;
    Lager value1 = (Lager) exprFactory.createValueExpression(elContext, "#{lager}", Lager.class).getValue(elContext);
    value1.drink();
    Lager value2 = (Lager) exprFactory.createValueExpression(elContext, "#{lager}", Lager.class).getValue(elContext);
    value2.drink();
    Lager value3 = (Lager) exprFactory.createValueExpression(elContext, "#{lager}", Lager.class).getValue(elContext);
    value3.drink();
    assertEquals(value1, value2);
    assertEquals(value2, value3);
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) Test(org.junit.Test)

Example 40 with ELContext

use of javax.el.ELContext in project oxCore by GluuFederation.

the class FacesMessages method evalAsString.

public String evalAsString(String expression) {
    if (facesContext == null) {
        return expression;
    }
    ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
    ELContext elContext = facesContext.getELContext();
    ValueExpression valueExpression = expressionFactory.createValueExpression(elContext, expression, String.class);
    String result = (String) valueExpression.getValue(elContext);
    return result;
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression)

Aggregations

ELContext (javax.el.ELContext)47 ValueExpression (javax.el.ValueExpression)31 Test (org.junit.Test)29 ExpressionFactory (javax.el.ExpressionFactory)22 ELContextImpl (org.apache.jasper.el.ELContextImpl)15 ValueReference (javax.el.ValueReference)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 UIComponent (javax.faces.component.UIComponent)7 ELException (javax.el.ELException)4 ELResolver (javax.el.ELResolver)4 BeanELResolver (javax.el.BeanELResolver)3 ArrayELResolver (javax.el.ArrayELResolver)2 CompositeELResolver (javax.el.CompositeELResolver)2 FunctionMapper (javax.el.FunctionMapper)2 ListELResolver (javax.el.ListELResolver)2 MapELResolver (javax.el.MapELResolver)2 ResourceBundleELResolver (javax.el.ResourceBundleELResolver)2 VariableMapper (javax.el.VariableMapper)2 FacesContext (javax.faces.context.FacesContext)2 ExpressionFactoryImpl (de.odysseus.el.ExpressionFactoryImpl)1