Pregunta

I am working on a method in a library. The method is passed a bean name and property name, and I would like to use ELResolver to retrieve the value of the property from the bean specified. Since the code is in a library (and for flexibility), the code doesn't have the bean name hard-coded in it.

Here is the code I am using:

elResolver.getValue( facesContext.getELContext(), elResolver.getValue(facesContext.getELContext(), null, myBean ), beanProperty )

The bean and properties are specified by myBean and beanProperty.

This seems to work, but is there a better way? I am using JSF 1.2 at the moment.

Thanks!

¿Fue útil?

Solución

Looks fine. Another way is

Object value = context.getApplication().evaluateExpressionGet(
    context, String.format("#{%s.%s}", myBean, beanProperty), Object.class);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top