Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

actualy my question is how to display a collection in my view : ex:

<h:outputText value="#{item.machineCollection.get(0).id != null ? item.machineCollection.get(0).id : ''}"/>

even after testing my code if the result is null i got this error

Array index out of range: 0

java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0 at java.util.Vector.get(Vector.java:694) at org.eclipse.persistence.indirection.IndirectList.get(IndirectList.java:401) at sun.reflect.GeneratedMethodAccessor194.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at javax.el.BeanELResolver.invokeMethod(BeanELResolver.java:779) at javax.el.BeanELResolver.invoke(BeanELResolver.java:528) at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:257) at com.sun.el.parser.AstValue.getValue(AstValue.java:134) at com.sun.el.parser.AstValue.getValue(AstValue.java:183) at com.sun.el.parser.AstNotEqual.getValue(AstNotEqual.java:58) at com.sun.el.parser.AstChoice.getValue(AstChoice.java:64) at com.sun.el.parser.AstDeferredExpression.getValue(AstDeferredExpression.java:63) at com.sun.el.parser.AstCompositeExpression.getValue(AstCompositeExpression.java:68) at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:224) at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50) at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109) at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194) at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182) at javax.faces.component.UIOutput.getValue(UIOutput.java:169) at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205) at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355) at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164) at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1764) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760) at org.primefaces.component.datatable.DataTableRenderer.encodeRegularCell(DataTableRenderer.java:741) at org.primefaces.component.datatable.DataTableRenderer.encodeRow(DataTableRenderer.java:693) at org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:601) at org.primefaces.component.datatable.DataTableRenderer.encodeRegularTable(DataTableRenderer.java:220) at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:192) at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:74) at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875) at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:59) at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:43) at org.primefaces.component.panel.PanelRenderer.encodeContent(PanelRenderer.java:198) at org.primefaces.component.panel.PanelRenderer.encodeMarkup(PanelRenderer.java:115) 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:1764) at javax.faces.render.Renderer.encodeChildren(Renderer.java:168) at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845) at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:55) at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:43) at org.primefaces.component.layout.LayoutUnitRenderer.encodeEnd(LayoutUnitRenderer.java:51) at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1764) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760) at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402) at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131) at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288) 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:1550) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281) 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 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231) at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860) at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056) at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229) 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:680)

if someone have a solution urgently pleas and thanks

share|improve this question
    
You want to print the list in the outputtext ? Why? –  Makky May 20 '13 at 13:32
    
You simple have a empty list on your page. check your server side code –  NullPointerException May 20 '13 at 13:34

2 Answers 2

up vote 2 down vote accepted

The problem is that you have

item.machineCollection.get(0).id

If you have an empty collection, item.machineCollection.get(0) will not work.

In primeface datatable you can use the var attribute. So if you add var="row" you can do

<p:datatable var="row" value="#{item.machineCollection}" >
    <p:column>
        <f:facet name="header">
            <h:outputText value="Id" />
        </f:facet>
        <h:outputText value="#{row.id}"/>
    </p:column>
....
</p:datatable>
share|improve this answer
    
ok but, how to get it if not null and return nothing if null without error ? –  MeursaultF May 20 '13 at 13:37
    
I'm not sure exactly what you wanted to do, but from your code and stack trace I'm guessing it's something similar to this. (I updated my answer) –  Simon May 20 '13 at 13:54
    
@user1643422 if the list is empty (i.e. it has null value or it doesn't contain any item) then the <p:dataTable> won't display anything at all. –  Luiggi Mendoza May 20 '13 at 14:16
    
yep, but even list return items, <p:dataTable> won't display anything... –  MeursaultF May 20 '13 at 14:37
2  
@user1643422 please use @username to answer a comment. The problem looks that your managed bean has a wrong scope, make sure it is at least @ViewScoped. –  Luiggi Mendoza May 20 '13 at 14:56

Use not empty operator:

<h:outputText value="#{not empty item.machineCollection ? item.machineCollection.get(0).id : ''}

or write custom JSF function, as described in this topic:

How to create a custom EL function?

share|improve this answer
    
i tryed #{! empty item.machineCollection.get(0).libelle} but range 0 exception come back .. :s –  MeursaultF May 20 '13 at 14:43
    
the code line was invisible in message, fixed format :) –  Donaudampfschifffreizeitfahrt May 20 '13 at 15:06
    
#{! empty item.machineCollection.get(0).libelle} –  MeursaultF May 20 '13 at 15:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.