JSF 2:如何将包含要调用的参数的操作传递给 Facelets 子视图(使用 ui:include 和 ui:param)? [英] JSF 2: how to pass an action including an argument to be invoked to a Facelets sub view (using ui:include and ui:param)?

查看:10
本文介绍了JSF 2:如何将包含要调用的参数的操作传递给 Facelets 子视图(使用 ui:include 和 ui:param)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这基本上是对this的扩展回答.

我试图在方法/操作调用中获取一个参数(用于列表/数据表中的删除按钮).

I am trying to get an argument into a method/action call (for a delete button in a list/data table).

客户:

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

子视图:

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

然而,JSF 失败并出现异常:

However, JSF fails with an exception saying:

...yadda, yadda
02:46:02,431 ERROR [stderr] (http--127.0.0.1-8080-5) Caused by: javax.el.MethodNotFoundException: /subviews/remove-doc-clink-popup.xhtml @37,98 action="#{acceptButtonBean[acceptButtonMethod]}": Method not found: com.company.project.beans.RepoHome@34b183e7.removeExternalDocument(89)()
02:46:02,431 ERROR [stderr] (http--127.0.0.1-8080-5)    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:109)
02:46:02,431 ERROR [stderr] (http--127.0.0.1-8080-5)    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
02:46:02,431 ERROR [stderr] (http--127.0.0.1-8080-5)    ... 31 more

注意

....RepoHome@34b183e7.removeExternalDocument(89)()

它不能那样工作.JSF 似乎无论如何都附加了括号.

It can't work that way. JSF seems to append parentheses no matters what.

能否以不同的方式实现,但仍使用上述技术?如果是,怎么办?

Can it be achieved differently, but still with the above technique? If so, how?

如果没有,为什么它不起作用?有规定吗?这是 Mojarra 2.0.x 的错误吗?如果存在其他括号,我认为省略括号没有问题...

If not, why isn't it working? Is it specified? Is it a bug with Mojarra 2.0.x? I see no problem to omit the parentheses in case of the presence of other parentheses...

请注意,我不是在寻找替代解决方案,例如使用 f:param、f:attribute 或 f:setPropertyActionListener.

Note I'm not looking for alternative solutions like using f:param, f:attribute, or f:setPropertyActionListener.

提前致谢

推荐答案

这确实不是有效的 EL.您不能在单个变量中混合方法名称和参数.这应该有效:

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>

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

请注意,这与 JSF 并不完全相关,而是与 EL 相关.如果它是一个错误或功能,您需要阅读 EL 规范或向 EL 人员报告,而不是 JSF 人员.JSF 在这里没有什么可指责的.EL 是一个完全独立的 API,JSF 恰好使用了它.

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.

更新:事实证明它适用于 Tomcat 7(可能还有任何其他具有 org.apache.el.* 实现的容器),但不适用于 Glassfish 3(使用 com.sun.el.* 实现).显示页面时失败,如下所示:

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*)

我检查了 EL 2.2 规范的第 1.19 章::>

I checked chapter 1.19 of the EL 2.2 spec:

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

而且我非常有信心 Tomcat 是正确的.是时候向 Glassfish 男孩报告错误了:GLASSFISH-17628.

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

更新 2:您似乎实际上在使用 JBoss 7.我不知道它使用的是 Tomcat 7 的哪个分支,但我可以确认我可以用 Tomcat 7.0 重现您的问题.19;按下按钮后失败如下:

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

成功运行时我使用的是 Tomcat 7.0.22,因此它已在 Tomcat 7.0.20 和 7.0.22 之间修复.

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.

这篇关于JSF 2:如何将包含要调用的参数的操作传递给 Facelets 子视图(使用 ui:include 和 ui:param)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆