gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 16:47:12 27 4
gpt4 key购买 nike

我正在尝试创建自己的数据表,就像 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>

最佳答案

根据 UIData#setValueExpression() javadoc,不允许在var中有EL表达式属性。

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

最好的办法是创建一个支持组件,您可以在其中手动评估和设置 var UIData 的属性组件绑定(bind)到 <h:dataTable>postAddToView期间事件。

<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> .

另见:

关于jsf - h :dataTable composite component, cc.attrs.var,IllegalArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36555893/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com