如何在ui中绑定组件:repeat?

时间:2016-01-25 10:49:15

标签: jsf jsf-2 binding uirepeat

我绑定了<ui:repeat>

中的组件
<ui:repeat var="item" value="#{eTManagedBean.capacity}"  varStatus="tableIndex">
<h:panelGrid binding="#{eTManagedBean.capacity[tableIndex.index].subGrid}" /></ui:repeat>

但它显示异常

  

ERROR   [org.apache.catalina.core.ContainerBase [jboss.web] [缺省主机]。[/ MDF-门户网页]。[面孔   Servlet]](http-localhost-127.0.0.1-8080-11)Servlet.service()for   servlet Faces Servlet抛出异常:   java.lang.IllegalArgumentException at   javax.el.ListELResolver.toInteger(ListELResolver.java:409)   [jboss-el-api_2.2_spec-1.0.0.Final.jar:1.0.0.Final] at   javax.el.ListELResolver.getValue(ListELResolver.java:199)   [jboss-el-api_2.2_spec-1.0.0.Final.jar:1.0.0.Final] at   com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)   [jsf-impl-2.1.7-jbossorg-2.jar:] at   com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)   [jsf-impl-2.1.7-jbossorg-2.jar:] at   org.apache.el.parser.AstValue.getTarget(AstValue.java:121)   [jbossweb-7.0.13.Final.jar:] at   org.apache.el.parser.AstValue.setValue(AstValue.java:196)   [jbossweb-7.0.13.Final.jar:] at   org.apache.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:257)   [jbossweb-7.0.13.Final.jar:] at   com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:131)   [jsf-impl-2.1.7-jbossorg-2.jar:] at   com.sun.faces.application.ApplicationImpl.createComponentApplyAnnotations(ApplicationImpl.java:1949)   [jsf-impl-2.1.7-jbossorg-2.jar:] at   com.sun.faces.application.ApplicationImpl.createComponent(ApplicationImpl.java:1144)   [jsf-impl-2.1.7-jbossorg-2.jar:] at   com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.createComponent(ComponentTagHandlerDelegateImpl.java:518)   [jsf-impl-2.1.7-jbossorg-2.jar:] at   com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:168)   [jsf-impl-2.1.7-jbossorg-2.jar:] at   javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)   [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final] at   javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)   [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final] at   javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)   [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final] at   org.richfaces.view.facelets.html.BehaviorsAddingComponentHandlerWrapper.applyNextHandler(BehaviorsAddingComponentHandlerWrapper.java:53)   [richfaces-components-ui-4.3.5.Final.jar:4.3.5.Final] at   com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:195)

当我尝试从var

进行访问时
<h:panelGrid id="mainGrid1"  binding="#{item.subGrid}" />

然后以

结束
  

ERROR [org.apache.catalina.core.ContainerBase。[jboss.web]。[default-host]。[/ mdf-portal-web]。[Faces Servlet]](http-localhost-127.0.0.1- 8080-10)servlet的Servlet.service()Faces Servlet抛出异常:javax.el.PropertyNotFoundException:/pages/TermCapacityCreation.xhtml @ 74,28 binding =&#34;#{item.subGrid}&#34;:Target无法访问,标识符&#39; item&#39;解析为null       at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:133)[jsf-impl-2.1.7-jbossorg-2.jar:]       at com.sun.faces.application.ApplicationImpl.createComponentApplyAnnotations(ApplicationImpl.java:1949)[jsf-impl-2.1.7-jbossorg-2.jar:]       at com.sun.faces.application.ApplicationImpl.createComponent(ApplicationImpl.java:1144)[jsf-impl-2.1.7-jbossorg-2.jar:]

在我的课堂上,我已经使用get/set方法

创建了对象
public class CapacityVO{
 //Other variable 
 private HtmlPanelGrid subGrid;
//get,set() method as well
}

1 个答案:

答案 0 :(得分:0)

这很奇怪,对于JSF实现来说很常见。最近,在2.0版之前,我曾使用<a4j:repeat>来克服这些问题。现在我认为最好使用<c:forEach> - 它只会起作用。

这是因为ui实现状态保存:重复为渲染时组件。