h:dataTable 复合组件,cc.attrs.var,IllegalArgumentException [英] h:dataTable composite component, cc.attrs.var, IllegalArgumentException
问题描述
我正在尝试像 primefaces 一样创建自己的数据表.问题是 cc.attrs.var
在使用时会抛出 IllegalArgumentException.所以我想知道如何拥有像 Primefaces 这样的 var 属性.
I'm trying to create my own dataTable like the primefaces one. The problem is that cc.attrs.var
when used throws a IllegalArgumentException. So I'm wondering how I can have the var attribute like Primefaces.
<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>
推荐答案
根据 UIData#setValueExpression()
javadoc,不允许有 EL 表达式var
属性.
抛出:IllegalArgumentException - 如果 name 是 id
、parent
、var
或 rowIndex
Throws: IllegalArgumentException - if name is one of
id
,parent
,var
, orrowIndex
最好的办法是创建一个支持组件,您可以在其中手动评估和设置 UIData
组件在
期间绑定到 >postAddToView
事件.
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>
.
这篇关于h:dataTable 复合组件,cc.attrs.var,IllegalArgumentException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!