You can modify this BalusC answer according to your needs.
Basically you can extend SpringBeanFacesELResolver
as you use it for EL resolver. However, EL resolver is looking for Spring Bean inside Spring Context. Source code give very good understanding what SpringBenFacesELResolver do.
Secondly you need javax.el.BeanELResolver
to access managed bean values as descriped in BalusC answer. I use Java Reflections for this purpose. javax.el.BeanELResolver
can be loaded inside SpringBeanFacesELResolver
dynamicly at run tim then invoke SpringBeanFacesELResolver#getValue
for nested properties just like in the referenced answer.
Here is the code:
public class ExtendedSpringELResolver extends SpringBeanFacesELResolver {
@Override
public Object getValue(ELContext context, Object base, Object property)
{
if (property == null || base == null || base instanceof ResourceBundle || base instanceof Map || base instanceof Collection) {
return null;
}
String propertyString = property.toString();
if (propertyString.contains(".")) {
Object value = base;
Class []params= new Class[]{ELContext.class,Object.class,Object.class};
for (String propertyPart : propertyString.split("\\.")) {
Class aClass = BeanELResolver.class;
try {
Method getValueMethod = aClass.getDeclaredMethod("getValue",params );
value = getValueMethod.invoke(aClass.newInstance(), context, value, propertyPart);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return value;
}
else {
return super.getValue(context, base, property);
}
}
}
P.S. I tried the code with the example in PrimeFaces showcase. I change String color
to Color color
where Color
is a user defined class for my case which has only a String proporty. I access the values by adding color.color
to columns list.
private String columnTemplate = "model manufacturer year color.color";
Car.PriceInformations
a collection? and do you want to access one of the item in the collection? – erencan