我正在尝试使用ui:repeat
标记迭代一组实体对象。迭代实体对象的集合时,iterable给出了类型为java.lang.Integer
的entityIds。我能够在我的java类中成功迭代Iterable<Integer>
,但是当我在EL(表达式语言)中使用ui:repeat
value
属性的迭代时,页面呈现失败发出这个例外:
SEVERE: Error Rendering View[/channelPages.xhtml]
javax.el.ELException: /channelPages.xhtml: Cannot convert px10.BusinessLayer.DBExecutions.ColNames_Iterable@4ae65b of type class px10.BusinessLayer.DBExecutions.ColNames_Iterable to class java.lang.Long
at com.sun.faces.facelets.compiler.AttributeInstruction.write(AttributeInstruction.java:96)
at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:54)
at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:45)
at org.primefaces.component.datalist.DataListRenderer.encodeList(DataListRenderer.java:148)
at org.primefaces.component.datalist.DataListRenderer.encodeMarkup(DataListRenderer.java:85)
at org.primefaces.component.datalist.DataListRenderer.encodeEnd(DataListRenderer.java:49)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:61)
at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:45)
at org.primefaces.component.panel.PanelRenderer.encodeContent(PanelRenderer.java:185)
at org.primefaces.component.panel.PanelRenderer.encodeMarkup(PanelRenderer.java:108)
at org.primefaces.component.panel.PanelRenderer.encodeEnd(PanelRenderer.java:55)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1763)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:401)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at px10.Security.AuthenticationFilter.doFilter(AuthenticationFilter.java:48)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.IllegalArgumentException: Cannot convert px10.BusinessLayer.DBExecutions.ColNames_Iterable@4ae65b of type class px10.BusinessLayer.DBExecutions.ColNames_Iterable to class java.lang.Long
at com.sun.el.lang.ELSupport.coerceToNumber(ELSupport.java:293)
at com.sun.el.lang.ELSupport.equals(ELSupport.java:154)
at com.sun.el.lang.ELSupport.compare(ELSupport.java:77)
at com.sun.el.parser.AstLessThan.getValue(AstLessThan.java:62)
at com.sun.el.parser.AstChoice.getValue(AstChoice.java:60)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:219)
at com.sun.faces.facelets.el.ELText$ELTextVariable.toString(ELText.java:214)
at com.sun.faces.facelets.compiler.AttributeInstruction.write(AttributeInstruction.java:89)
... 58 more
这是我在实体集合中迭代entityObjects的id时使用的Iterable
实现。
public class ColNames_Iterable<N> implements Iterable<N> {
private List<HColumn> columnsList;
public ColNames_Iterable(List<HColumn> columnsList) {
this.columnsList = columnsList;
}
@Override
public Iterator<N> iterator() {
return new ColNamesIterator(columnsList.iterator());
}
public int getSize() {
return columnsList.size();
}
public class ColNamesIterator<K, N, V> implements Iterator<N> {
private Iterator<HColumn<N, V>> original;
public ColNamesIterator(Iterator<HColumn<N, V>> original) {
this.original = original;
}
@Override
public N next() {
return original.next().getName();
}
@Override
public boolean hasNext() {
return original.hasNext();
}
@Override
public void remove() {
original.remove();
}
}
}
然而,我发现另一个Iterable(实际上是一个Arraylist)正在成功迭代。但迭代我的iterable在java类中也是成功的,但不在EL内部。
JSF 2.1.6 Glassfish 3.1
答案 0 :(得分:4)
根据tag documentation,<ui:repeat>
值仅支持以下类型:
该集合可以是
List
,数组,java.sql.ResultSet
或单个javaObject
。如果集合为null
,则此标记不执行任何操作。
您需要将其变为List
。