Rajat Gupta
Rajat Gupta

Reputation: 26587

Iteration over an Iterable<Integer> fails within ui:repeat

I'm trying to iterate over a collection of entity objects using ui:repeat tags. While iterating over the collection of entity objects, the iterable gives out entityIds of type java.lang.Integer. I'm able to successfully iterate over the Iterable<Integer> in my java classes but when I use this iterable inside the EL(expression language) with ui:repeat's value attribute, the page rendering fails giving out this exception:

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

Here is my Iterable implementation that is used while iterating over the ids of the entityObjects in collection of entities.

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();
        }
    }
}

However I found that another Iterable (actually an Arraylist) is being successfully iterated. But iteration over my iterable is also successful within java class but not inside EL.

Using :

JSF 2.1.6 on Glassfish 3.1

Upvotes: 1

Views: 1481

Answers (1)

BalusC
BalusC

Reputation: 1108632

According to the tag documentation the <ui:repeat> value supports only the following types:

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

You need to turn it into a List.

Upvotes: 4

Related Questions