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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations