JSF 2: how to pass an action including an argument to be invoked to a Facelets sub view (using ui:include and ui:param)?

徘徊边缘 提交于 2019-11-27 13:50:22

That's indeed not valid EL. You cannot mix method names and arguments in a single variable. This should work:

<ui:include src="...">
  <ui:param name="acceptButtonBean" value="#{repoHome}" />
  <ui:param name="acceptButtonAction" value="removeIndividualDocument" />
  <ui:param name="acceptButtonArgument" value="#{doc.id}" />
</ui:include>

with

<h:commandButton value="Continue"
    action="#{acceptButtonBean[acceptButtonAction](acceptButtonArgument)}" />

Note that this is not exactly related to JSF, but to EL. If it were a bug or a feature, you'd need to read up the EL specification or report to the EL guys, not the JSF one. JSF is nothing to blame here. EL is an entirely standalone API which JSF just happens to use.


Update: it turns out that it works on Tomcat 7 (and likely any other container with org.apache.el.* implementation), but not on Glassfish 3 (with com.sun.el.* implementation). It fails as follows while displaying the page:

Caused by: javax.el.ELException: Error Parsing: #{p1[p2](p3)}
    at com.sun.el.lang.ExpressionBuilder.createNodeInternal(ExpressionBuilder.java:174)
    at com.sun.el.lang.ExpressionBuilder.build(ExpressionBuilder.java:191)
    at com.sun.el.lang.ExpressionBuilder.createMethodExpression(ExpressionBuilder.java:242)
    at com.sun.el.ExpressionFactoryImpl.createMethodExpression(ExpressionFactoryImpl.java:81)
    at org.jboss.weld.util.el.ForwardingExpressionFactory.createMethodExpression(ForwardingExpressionFactory.java:43)
    at org.jboss.weld.el.WeldExpressionFactory.createMethodExpression(WeldExpressionFactory.java:62)
    at com.sun.faces.facelets.tag.TagAttributeImpl.getMethodExpression(TagAttributeImpl.java:222)
    ... 63 more
Caused by: com.sun.el.parser.ParseException: Encountered "(" at line 1, column 9.
Was expecting one of:
        (*snip*)

I checked chapter 1.19 of the EL 2.2 spec:

 ValueSuffix      ::= ‘.’ Identifier MethodParameters?
                    | ‘[‘ Expression ‘]’ MethodParameters?          <-- Look here
 MethodParameters ::= '(' (Expression (‘,’ Expression )* )? ')'

and I am pretty confident that Tomcat is right. It's time to report a bug to Glassfish boys: GLASSFISH-17628.


Update 2: you seem to be actually using JBoss 7. I don't know what fork of Tomcat 7 exactly it uses, but I can confirm that I can reproduce your problem with Tomcat 7.0.19; it fails as follows after pressing the button:

Caused by: javax.el.MethodNotFoundException: /test.xhtml @22,62 action="#{p1[p2](p3)}": Method not found: com.example.Bean@2616aa35.submit(java.lang.String)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:109)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
    ... 24 more

I was using Tomcat 7.0.22 when it ran successfully, so it has been fixed somewhere between Tomcat 7.0.20 and 7.0.22.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!