5

在 JSF 1.2 中,一个是使用 Java List 列出项目:

private List<Customer> customerItems = null;

,但在 JSF 2.0 JSf DataModel (ListDataModel) 是要走的路。(我正在使用 JSF 2.0)

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

但是,我仍然不知道如何有效地使用它。更确切地说,我什至无法实现一个简单且强制性的案例,即导航。

我有一个<h:datatablevalue="#{customerController}" var="customer"> 从名为“customerController”的客户托管 bean 获取其行对象。

最后一列包含一个命令链接,该链接调用一个方法来查看所选行的详细信息页面。它工作正常。

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

在给定自定义的详细视图页面中,我有一个包含订单列表的数据表,一切都很好,表格已填充,订单显示为与订单属性对应的几列。

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

此相同数据表的最后一列包含一个命令链接,用于导航到所选订单的详细信息页面:

痛苦来了。我得到无可用行异常:

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

谢谢您的帮助。

4

1 回答 1

1

首先检查您的 customerBean 的范围,它应该是viewScopedSessionScoped

另一件事可能是glassfish的问题,它需要在 xml 文件中配置maven 依赖项。请参阅此链接。http://mavenhub.com/c/javax/faces/model/norowavailableexception 最后要检查的是您的列表。尝试调试它并查看它列出了您在 UI 上填充的所有属性。

于 2013-08-13T04:32:15.820 回答