我想要實現這個使用動態參數值表達式:嵌套JSF表達串
<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;
}
}
不,我說的是正確的:'公開名單 getSomeValue(){...}' –