h:dataTable composite component, cc.attrs.var, IllegalArgumentException

一个人想着一个人 提交于 2019-12-01 08:14:55
BalusC

As per the UIData#setValueExpression() javadoc, it's not allowed to have an EL expression in var attribute.

Throws: IllegalArgumentException - if name is one of id, parent, var, or rowIndex

Your best bet is to create a backing component wherein you manually evaluate and set the var attribute of the UIData component bound to <h:dataTable> during the postAddToView event.

<cc:interface componentType="yourTableComposite">
    <cc:attribute name="value" />
    <cc:attribute name="var" />
</cc:interface>
<cc:implementation>
    <f:event type="postAddToView" listener="#{cc.init}" />

    <h:dataTable binding="#{cc.table}" value="#{cc.attrs.value}">
        <cc:insertChildren />
    </h:dataTable>
</cc:implementation>

@FacesComponent("yourTableComposite")
public class YourTableComposite extends UINamingContainer {

    private UIData table;

    public void init() {
        table.setVar((String) getAttributes().get("var"));
    }

    public UIData getTable() {
        return table;
    }

    public void setTable(UIData table) {
        this.table = table;
    }

}

Note that I fixed the <ui:insert> to be <cc:insertChildren>. The <ui:insert> can only be used in <ui:composition>/<ui:decorate>.

See also:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!