필요에 따라 this BalusC answer을 수정할 수 있습니다.
기본적으로 SpringBeanFacesELResolver
은 EL 해결 프로그램에 사용할 때 확장 할 수 있습니다. 그러나 EL 해석자는 Spring 컨텍스트 내에서 Spring Bean을 찾고있다. Source code은 SpringBenFacesELResolver의 기능을 잘 이해하고 있습니다.
두 번째로 BalusC 응답에서 설명하는대로 관리 빈 값에 액세스하려면 javax.el.BeanELResolver
이 필요합니다. 이 목적을 위해 Java Reflections를 사용합니다. javax.el.BeanELResolver
은 실행 시간에 SpringBeanFacesELResolver
동적으로로드 할 수 있으며 참조 된 응답과 마찬가지로 중첩 된 속성의 경우 SpringBeanFacesELResolver#getValue
을 호출합니다.
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);
}
}
}
추신 : 여기
코드입니다
PrimeFaces showcase에 예제 코드가 있습니다. 나는
String color
을
Color color
으로 바꾼다.
Color
은 단지 String 비례가있는 내 케이스의 사용자 정의 클래스이다. 열 목록에
color.color
을 추가하여 값에 액세스합니다.
private String columnTemplate = "model manufacturer year color.color";
은'Car.PriceInformations' 컬렉션입니까? 컬렉션의 항목 중 하나에 액세스 하시겠습니까? – erencan
자바 클래스에서 동일한 속성에 액세스하려고 시도하십시오. 편집기가이 표현식에 대한 오류/제안을 표시 할 수 있으므로 액세스 할 수 있습니까? – Jitesh
@erencan 컬렉션이 아닙니다. 그냥 객체 –