gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 01:35:21 24 4
gpt4 key购买 nike

这基本上是对 this answer 的扩展.

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

客户:

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

subview :

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

但是,JSF 失败并出现异常:

...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 似乎无论如何都会附加括号。

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

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

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

提前致谢

最佳答案

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

<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 恰好使用了它。


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

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 spec 的第 1.19 章:

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

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


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

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 之间。

关于jsf-2 - JSF 2 : how to pass an action including an argument to be invoked to a Facelets sub view (using ui:include and ui:param)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8004233/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com