gpt4 book ai didi

java - 在 ui :repeat 内对 Iterable 的迭代失败

转载 作者:行者123 更新时间:2023-11-29 03:46:58 25 4
gpt4 key购买 nike

我正在尝试使用 ui:repeat 遍历实体对象的集合标签。在遍历实体对象集合时,可迭代对象给出类型为 java.lang.Integer 的 entityIds .我能够成功地遍历 Iterable<Integer>在我的 java 类中,但是当我在 EL(表达式语言)中使用此可迭代对象时 ui:repeatvalue属性,页面呈现失败给出此异常:

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

这是我的 Iterable在实体集合中迭代实体对象的 ID 时使用的实现。

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)正在迭代成功。但是在 Java 类中对我的可迭代对象的迭代也成功了,但在 EL 中却没有。

使用:

JSF 2.1.6 上玻璃鱼 3.1

最佳答案

根据tag documentation <ui:repeat>值仅支持以下类型:

The collection may be a List, array, java.sql.ResultSet, or an individual java Object. If the collection is null, this tag does nothing.

你需要把它变成一个List .

关于java - 在 ui :repeat 内对 Iterable<Integer> 的迭代失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10461697/

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