1

ui:repeat我正在尝试使用标签迭代实体对象的集合。在迭代实体对象的集合时,可迭代对象会给出 type 的 entityIds java.lang.Integer。我能够成功地在我的 java 类中迭代,但是当我在具有'属性Iterable<Integer>的 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在迭代实体集合中 entityObjects 的 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 中却没有。

使用 :

Glassfish 3.1 上的 JSF 2.1.6

4

1 回答 1

4

根据标签文档,该<ui:repeat>值仅支持以下类型:

集合可以是List、数组、java.sql.ResultSet或单独的 java Object。如果集合是null,则此标签不执行任何操作。

你需要把它变成一个List.

于 2012-05-05T12:14:20.667 回答