@Override public ValueReference getValueReference(EvaluationContext ctx) { VariableMapper varMapper = ctx.getVariableMapper(); if (varMapper == null) { return null; } ValueExpression expr = varMapper.resolveVariable(this.image); if (expr == null) { return null; } return expr.getValueReference(ctx); }
@Test public void testGetValueReference() { ExpressionFactory factory = ExpressionFactory.newInstance(); ELContext context = new ELContextImpl(); TesterBeanB beanB = new TesterBeanB(); beanB.setName("Tomcat"); ValueExpression var = factory.createValueExpression(beanB, TesterBeanB.class); context.getVariableMapper().setVariable("beanB", var); ValueExpression ve = factory.createValueExpression( context, "${beanB.name}", String.class); // First check the basics work String result = (String) ve.getValue(context); assertEquals("Tomcat", result); // Now check the value reference ValueReference vr = ve.getValueReference(context); assertNotNull(vr); assertEquals(beanB, vr.getBase()); assertEquals("name", vr.getProperty()); }
public ValueReference getValueReference(ELContext elContext) { InterceptingResolver resolver = new InterceptingResolver(elContext.getELResolver()); try { expression.setValue(decorateELContext(elContext, resolver), null); } catch (ELException ele) { return null; } ValueReference reference = resolver.getValueReference(); if (reference != null) { Object base = reference.getBase(); if (base instanceof CompositeComponentExpressionHolder) { ValueExpression ve = ((CompositeComponentExpressionHolder) base) .getExpression((String) reference.getProperty()); if (ve != null) { this.expression = ve; reference = getValueReference(elContext); } } } return reference; }
/** * @since EL 2.2 */ @Override public ValueReference getValueReference(EvaluationContext ctx) { // Check this is a reference to a base and a property if (this.children.length > 2 && this.jjtGetChild(2) instanceof AstMethodParameters) { // This is a method call return null; } Target t = getTarget(ctx); return new ValueReference(t.base, t.property); }
/** * @since EL 2.2 */ @Override public ValueReference getValueReference(ELContext context) { EvaluationContext ctx = new EvaluationContext(context, this.fnMapper, this.varMapper); return this.getNode().getValueReference(ctx); }
@Test public void testGetValueReferenceVariable() { ExpressionFactory factory = ExpressionFactory.newInstance(); ELContext context = new ELContextImpl(); TesterBeanB beanB = new TesterBeanB(); beanB.setName("Tomcat"); ValueExpression var = factory.createValueExpression(beanB, TesterBeanB.class); context.getVariableMapper().setVariable("beanB", var); ValueExpression var2 = factory.createValueExpression( context, "${beanB.name}", String.class); context.getVariableMapper().setVariable("foo", var2); ValueExpression ve = factory.createValueExpression( context, "${foo}", ValueExpression.class); // Now check the value reference ValueReference vr = ve.getValueReference(context); assertNotNull(vr); assertEquals(beanB, vr.getBase()); assertEquals("name", vr.getProperty()); }
@Test public void testBug49345() { ExpressionFactory factory = ExpressionFactory.newInstance(); ELContext context = new ELContextImpl(); TesterBeanA beanA = new TesterBeanA(); TesterBeanB beanB = new TesterBeanB(); beanB.setName("Tomcat"); beanA.setBean(beanB); ValueExpression var = factory.createValueExpression(beanA, TesterBeanA.class); context.getVariableMapper().setVariable("beanA", var); ValueExpression ve = factory.createValueExpression( context, "${beanA.bean.name}", String.class); // First check the basics work String result = (String) ve.getValue(context); assertEquals("Tomcat", result); // Now check the value reference ValueReference vr = ve.getValueReference(context); assertNotNull(vr); assertEquals(beanB, vr.getBase()); assertEquals("name", vr.getProperty()); }
/** * Which annotations are given to an object described by an EL expression? * * @param p_expression * EL expression of the JSF bean attribute * @return null if there are no annotations, or if they cannot be accessed */ public static Annotation[] readAnnotations(ValueExpression p_expression, UIComponent p_component) { FacesContext context = FacesContext.getCurrentInstance(); ELContext elContext = context.getELContext(); try { ValueReference valueReference = p_expression.getValueReference(elContext); Object base; if (null == valueReference) { base = evaluteBaseForMojarra(elContext, p_expression); } else { base = valueReference.getBase(); } if (null == base) { return null; } Field declaredField = getField(base, p_expression.getExpressionString()); if (null != declaredField) { return declaredField.getAnnotations(); } Method getter = getGetter(base, p_expression.getExpressionString()); if (null != getter) { return getter.getAnnotations(); } } catch (PropertyNotFoundException ex) { // this happens if a bean is null. That's a legal state, so suffice it to return no annotation. } return null; }
@Override public void setValue(ELContext context, Object base, Object property, Object value) { if (base != null && property != null) { context.setPropertyResolved(true); valueReference = new ValueReference(base, property.toString()); } }
/** * @since EL 2.2 */ @Override public ValueReference getValueReference(EvaluationContext ctx) { return null; }