问题描述
我正在尝试创建自己的数据表,如原理图。问题是,当使用的时候, cc.attrs.var
会抛出一个IllegalArgumentException异常。所以我想知道我如何可以使用如原型的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>
推荐答案
根据 javadoc,不允许在 var
属性中有EL表达式。
As per the UIData#setValueExpression()
javadoc, it's not allowed to have an EL expression in var
attribute.
你最好的办法是创建一个支持组件,您可以手动评估并设置组件在 postAddToView
事件中绑定到< h:dataTable>
。
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;
}
}
请注意,我修复了< ui:insert>
为< cc:insertChildren>
。 < ui:insert>
只能在< ui:composition>
/ < ui:decorate>
。
Note that I fixed the <ui:insert>
to be <cc:insertChildren>
. The <ui:insert>
can only be used in <ui:composition>
/<ui:decorate>
.
- Initialize a composite component based on the provided attributes
- How does the 'binding' attribute work in JSF? When and how should it be used?
这篇关于h:dataTable复合组件,cc.attrs.var,IllegalArgumentException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!