我想使用值表达式的动态参数来实现这一点:
<h:dataTable value="#{someBean.someValue}" var="field">
<h:column>#{anotherBean[field]}</h:column>
</h:dataTable>
field
在哪里'user.name'
或'location.address.zip'
或...
是否可以?
请注意,这是一个简单的示例,我感兴趣的ValueExpression
不是dataTable
组件。
UPDATE 现在的问题是:如何替换标准的BeanELResolver?
在 ELUtils 中查找:
...
composite.addRootELResolver(IMPLICIT_RESOLVER);
composite.add(FLASH_RESOLVER);
composite.addPropertyELResolver(COMPOSITE_COMPONENT_ATTRIBUTES_EL_RESOLVER);
addELResolvers(composite, associate.getELResolversFromFacesConfig());
addVariableResolvers(composite, FacesCompositeELResolver.ELResolverChainType.Faces,
associate);
addPropertyResolvers(composite, associate);
composite.add(associate.getApplicationELResolvers());
composite.addRootELResolver(MANAGED_BEAN_RESOLVER);
composite.addPropertyELResolver(RESOURCE_RESOLVER);
composite.addPropertyELResolver(BUNDLE_RESOLVER);
...
但我还没有完全理解解析器链......所以我会去学习:)
更新 2
此代码有效;)
public class ExtendedBeanELResolver extends BeanELResolver
{
@Override
public Object getValue(ELContext context, Object base, Object property) throws NullPointerException, PropertyNotFoundException, ELException
{
try
{
return super.getValue(context, base, property);
}
catch(PropertyNotFoundException e)
{
try
{
Object value = base;
for(String part : property.toString().split("\\."))
{
value = super.getValue(context, value, part);
}
return value;
}
catch(PropertyNotFoundException e1)
{
context.setPropertyResolved(false);
}
}
return null;
}
}