Jsf h:dataTable复合组件,cc.attrs.var,IllegalArgumentException

Jsf h:dataTable复合组件,cc.attrs.var,IllegalArgumentException,jsf,datatable,composite-component,Jsf,Datatable,Composite Component,我正在尝试创建自己的数据表,就像primefaces表一样。问题是cc.attrs.var在使用时抛出一个IllegalArgumentException。所以我想知道如何像Primefaces一样使用var属性 <cc:interface> <cc:attribute name="value"/> <cc:attribute name="var"/> <cc:attribute name="styleClass"/> &l

我正在尝试创建自己的数据表,就像primefaces表一样。问题是
cc.attrs.var
在使用时抛出一个IllegalArgumentException。所以我想知道如何像Primefaces一样使用var属性

<cc:interface>
    <cc:attribute name="value"/>
    <cc:attribute name="var"/>
    <cc:attribute name="styleClass"/>
</cc:interface>

<cc:implementation>

    <div>Previous</div>
    <div>Next</div>

    <h:dataTable value="#{cc.attrs.value}" var="#{cc.attrs.var}" styleClass="#{cc.attrs.styleClass}">
        <ui:insert/>
    </h:dataTable>

</cc:implementation>

以前的
下一个
根据javadoc,在
var
属性中不允许有EL表达式

抛出: IllegalArgumentException-如果名称是
id
parent
var
rowIndex

最好的方法是创建一个支持组件,在
postAddToView
事件期间手动计算并设置绑定到
的组件的
var
属性

<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;
    }

}