Jsf DataModel vs Java List problem ( no row available exception )

Hanynowsky picture Hanynowsky · Jun 17, 2011 · Viewed 8k times · Source

In JSF 1.2 One was listing Items using Java List :

private List<Customer> customerItems = null;

, but in JSF 2.0 JSf DataModel (ListDataModel) is the way to go. (I am using JSF 2.0)

private DataModel customerItems = null;
 public abstract DataModel createPageDataModel();

However, I still don't get how to efficiently work with it. Rather say, I can't even implement a simple and mandatory case which is, navigation.

I have a <h:datatable value="#{customerController}" var="customer"> that gets its row objects from Customer managed bean named "customerController".

the last column holds a command link that calls a method to viewing the details page of the selected row. It is working fine.

<h:column>
<h:commandButton value="View me"  action="#{customerController.prepareDetails}"/>
</h:column>

When in the detail view page of given custom, I have a data table that holds a list of orders Everything is fine, the table is populated and the orders are displayed with several columns corresponding to the order attributes.

.....
<h:outputText value="customer.selected.name"  />
 <h:datatable value="#{customer.selected.orderList}" var="order">
......

This same datatable's last column holds a command link to navigating to the detail page of the selected order:

And here comes the pain. I get No Row Available Exception :

javax.faces.model.NoRowAvailableException
- Stack Trace

javax.faces.el.EvaluationException: javax.faces.model.NoRowAvailableException
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIData.broadcast(UIData.java:1093)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:409)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1534)
    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 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:326)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:227)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:170)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1013)
    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: javax.faces.model.NoRowAvailableException
    at javax.faces.model.ListDataModel.getRowData(ListDataModel.java:150)
    at jsf.EvaluationController.prepareView(EvaluationController.java:82)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:234)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
    ... 34 more

Thank you for your help.

Answer

tusharagrawa picture tusharagrawa · Aug 13, 2013

Firstly check the scope of your customerBean it should be either a viewScoped or SessionScoped.

Another thing could be a problem of glassfish which needs a maven dependency configured in the xml files.See this link. http://mavenhub.com/c/javax/faces/model/norowavailableexception Last thing to check is your list.Try to debug it and see it has all the properties listed in it which you are populating it on the UI.