将 h:commandButton 和 f:param 添加到 h:dataTable 时出现 IllegalArgumentException
目前我正在使用数据表来显示数据库中的一些项目。工作正常。
<h:dataTable border="1" value="#{overviewBean.loadContent }" var="item" first="0" >
<h:column id="column1">
<f:facet name="header">
<h:outputText value="#{messages.overviewSubscriptionID }"></h:outputText>
</f:facet>
<h:outputText value="#{item.subscriptionID }"></h:outputText>
</h:column>
<h:column id="column2">
<f:facet name="header">
<h:outputText value="#{messages.overviewCourseID}"></h:outputText>
</f:facet>
<h:outputText value="#{item.courseID }"></h:outputText>
</h:column>
...
<h:column id="column13">
<f:facet name="header">
<h:outputText value="#{messages.overviewDeleteItem }"></h:outputText>
</f:facet>
<h:commandButton action="#{overviewBean.delete}" value="X">
<f:param name="delete" value="#{item.courseID}"></f:param>
</h:commandButton>
</h:column>
</h:dataTable>
现在只要有 param-tag 存在,页面就不会加载。这是抛出的异常:
/overview.jsp(15,1) '#{overviewBean.loadContent }' java.lang.IllegalArgumentException
Caused by:
java.lang.IllegalArgumentException - java.lang.IllegalArgumentException
Edit: Because requested, I added the entire stacktrace (as seen on the generated page):
org.apache.jasper.el.JspELException: /overview.jsp(15,1) '#{overviewBean.loadContent }' java.lang.IllegalArgumentException
at org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:107)
at javax.faces.component.UIData.getValue(UIData.java:1142)
at javax.faces.component.UIData.createDataModel(UIData.java:1082)
at javax.faces.component.UIData.getDataModel(UIData.java:1056)
at javax.faces.component.UIData.getRowCount(UIData.java:449)
at org.apache.myfaces.shared_impl.renderkit.html.HtmlTableRendererBase.encodeInnerHtml(HtmlTableRendererBase.java:234)
at org.apache.myfaces.shared_impl.renderkit.html.HtmlTableRendererBase.encodeChildren(HtmlTableRendererBase.java:143)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:627)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:250)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:257)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:257)
at org.apache.myfaces.application.jsp.JspViewHandlerImpl.actuallyRenderView(JspViewHandlerImpl.java:427)
at org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:383)
at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:140)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:187)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
Caused by: javax.faces.el.EvaluationException: java.lang.IllegalArgumentException
at org.apache.myfaces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:80)
at org.apache.myfaces.el.convert.VariableResolverToELResolver.getValue(VariableResolverToELResolver.java:95)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:68)
at org.apache.el.parser.AstValue.getValue(AstValue.java:112)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
at org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:101)
... 27 more
Caused by: javax.el.ELException: java.lang.IllegalArgumentException
at javax.el.BeanELResolver.setValue(BeanELResolver.java:116)
at javax.el.CompositeELResolver.setValue(CompositeELResolver.java:69)
at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.setValue(FacesCompositeELResolver.java:182)
at org.apache.myfaces.config.ManagedBeanBuilder.initializeProperties(ManagedBeanBuilder.java:268)
at org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean(ManagedBeanBuilder.java:92)
at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.createManagedBean(ManagedBeanResolver.java:198)
at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.getValue(ManagedBeanResolver.java:164)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
at org.apache.myfaces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:65)
... 34 more
Caused by: java.lang.IllegalArgumentException
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 javax.el.BeanELResolver.setValue(BeanELResolver.java:108)
... 43 more
Edit 2: Here's a link to the page that's actually generated: index_jsp.html
有什么想法吗? 该 bean 已注册并且工作正常。删除方法也存在。 (列 ID 也是正确的)
Currently I'm using a datatable to display some items out of a database. Works fine.
<h:dataTable border="1" value="#{overviewBean.loadContent }" var="item" first="0" >
<h:column id="column1">
<f:facet name="header">
<h:outputText value="#{messages.overviewSubscriptionID }"></h:outputText>
</f:facet>
<h:outputText value="#{item.subscriptionID }"></h:outputText>
</h:column>
<h:column id="column2">
<f:facet name="header">
<h:outputText value="#{messages.overviewCourseID}"></h:outputText>
</f:facet>
<h:outputText value="#{item.courseID }"></h:outputText>
</h:column>
...
<h:column id="column13">
<f:facet name="header">
<h:outputText value="#{messages.overviewDeleteItem }"></h:outputText>
</f:facet>
<h:commandButton action="#{overviewBean.delete}" value="X">
<f:param name="delete" value="#{item.courseID}"></f:param>
</h:commandButton>
</h:column>
</h:dataTable>
Whenever now the param-tag is there, the page doesn't load. This is the exception that is thrown:
/overview.jsp(15,1) '#{overviewBean.loadContent }' java.lang.IllegalArgumentException
Caused by:
java.lang.IllegalArgumentException - java.lang.IllegalArgumentException
Edit: Because requested, I added the entire stacktrace (as seen on the generated page):
org.apache.jasper.el.JspELException: /overview.jsp(15,1) '#{overviewBean.loadContent }' java.lang.IllegalArgumentException
at org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:107)
at javax.faces.component.UIData.getValue(UIData.java:1142)
at javax.faces.component.UIData.createDataModel(UIData.java:1082)
at javax.faces.component.UIData.getDataModel(UIData.java:1056)
at javax.faces.component.UIData.getRowCount(UIData.java:449)
at org.apache.myfaces.shared_impl.renderkit.html.HtmlTableRendererBase.encodeInnerHtml(HtmlTableRendererBase.java:234)
at org.apache.myfaces.shared_impl.renderkit.html.HtmlTableRendererBase.encodeChildren(HtmlTableRendererBase.java:143)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:627)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:250)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:257)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:257)
at org.apache.myfaces.application.jsp.JspViewHandlerImpl.actuallyRenderView(JspViewHandlerImpl.java:427)
at org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:383)
at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:140)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:187)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
Caused by: javax.faces.el.EvaluationException: java.lang.IllegalArgumentException
at org.apache.myfaces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:80)
at org.apache.myfaces.el.convert.VariableResolverToELResolver.getValue(VariableResolverToELResolver.java:95)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:68)
at org.apache.el.parser.AstValue.getValue(AstValue.java:112)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
at org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:101)
... 27 more
Caused by: javax.el.ELException: java.lang.IllegalArgumentException
at javax.el.BeanELResolver.setValue(BeanELResolver.java:116)
at javax.el.CompositeELResolver.setValue(CompositeELResolver.java:69)
at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.setValue(FacesCompositeELResolver.java:182)
at org.apache.myfaces.config.ManagedBeanBuilder.initializeProperties(ManagedBeanBuilder.java:268)
at org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean(ManagedBeanBuilder.java:92)
at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.createManagedBean(ManagedBeanResolver.java:198)
at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.getValue(ManagedBeanResolver.java:164)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
at org.apache.myfaces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:65)
... 34 more
Caused by: java.lang.IllegalArgumentException
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 javax.el.BeanELResolver.setValue(BeanELResolver.java:108)
... 43 more
Edit 2: Here's a link to the page that's actually generated: index_jsp.html
Any idea?
The bean is registered and otherwise working correctly. The method delete exists as well. (The column id's are correct, too)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据堆栈跟踪,您正在使用 MyFaces。这可能是 MyFaces 特有的,我从未在 Mojarra 上见过这个,我已经使用了很多年了。
至少,在
h:commandButton
中使用f:param
在 JSF 1.x 上是行不通的。它仅适用于h:commandLink
。另一方面,您应该将数据表的值包装在DataModel
中,以便您可以获得按下按钮的行。或者,如果您使用的是 JSF 1.2,则还可以使用f:setPropertyActionListener
。您可以在此答案中找到示例。Based on the stacktrace, you're using MyFaces. This might be MyFaces specific, I've never seen this on Mojarra, which I'm already using for years.
At least, using
f:param
in ah:commandButton
wouldn't have worked on JSF 1.x anyway. It works onh:commandLink
only. On the other hand, you should be wrapping the datatable's value in aDataModel
so that you can obtain the row where the button was pressed. Alternatively, if you're on JSF 1.2, you can also use thef:setPropertyActionListener
. You can find examples in this answer.