我正在使用 primefaces 库提供的动态列功能。因为我也有嵌套属性(例如 bean.city.address),所以我制作了一个自定义 BeanElResolver 来处理它:
public class ExtendedBeanELResolver extends BeanELResolver {
@Override
public Object getValue(ELContext context, Object base, Object property)
throws NullPointerException, PropertyNotFoundException, ELException
{
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;
for (String propertyPart : propertyString.split("\\.")) {
value = super.getValue(context, value, propertyPart);
}
return value;
}
else {
return super.getValue(context, base, property);
}
}
它适用于 bean 属性,但是当呈现页面时,我在 primefaces 中为某些图像获得 PropertyNotFound Exception,这不是 bean 属性:
Servlet failed with an Exception -javax.el.PropertyNotFoundException: The class 'org.primefaces.application.PrimeResourceHandler' does not have the property 'primefaces- aristo:images/ui-bg_highlight-soft_100_c4c4c4_1x100.png'.
我认为那是因为我扩展了 BeanELResolver 类,它以某种方式覆盖了处理各种属性的默认 ELResolver。我试图创建一个 CompositeELResolver 类来处理其他类型的属性,但我不知道如何。有任何想法吗?