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

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

问题描述

这基本上是对此内容的扩展答案.

我正在尝试将一个参数传入方法/操作调用中(用于列表/数据表中的删除按钮).

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是否有bug?如果出现其他括号,我认为可以省略括号...

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是JSF恰好使用的完全独立的API.

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:您似乎实际上正在使用JBoss7.我不知道它确切使用了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天全站免登陆