在JSF中不是有效的方法表达式 [英] Not A Valid Method Expression in JSF

查看:107
本文介绍了在JSF中不是有效的方法表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个命令按钮,我想使用它来导航到另一个jsf facelet,但是我得到的不是有效的方法表达式:

I have a commandbutton that I want to use to navigate to another jsf facelet, but I am getting a not a valid method expression:

 <h:commandButton value="Save Edits" action="editOrDeletePage.xhtml?editing=true;#{product.id};name=#{product.productName};description=#{product.description};quantity=#{product.quantity}"/>

如果只有

action="editOrDeletePage.xhtml?editing=true"

我猜想我要传递的多个属性时,不会正确地分隔它们.有什么想法吗?

I guess when I have multiple properties that I'm passing, I am not delimiting them correctly. Any ideas?

推荐答案

action属性包含EL表达式时,它将被解释为方法表达式.因此,它仅在使用action="#{bean.someMethod}"时才有效.但是,您的尝试并不代表有效的方法表达式,而是代表了action属性不接受的值表达式.

When the action attribute contains an EL expression, it's interpreted as a method expression. It's thus really only valid when you use action="#{bean.someMethod}". However, your attempt does not represent a valid method expression, it's represents instead a value expression which is not accepted by the action attribute.

如果您打算将其他请求/视图参数附加到表单提交中,则应该使用<f:param>.

If you intend to append additional request/view parameters to the form submit, then you should rather use <f:param>.

<h:commandButton value="Save Edits" action="editOrDeletePage.xhtml">
    <f:param name="editing" value="true" />
    <f:param name="id" value="#{product.id}" />
    <f:param name="name" value="#{product.productName}" />
    <f:param name="description" value="#{product.description}" />
    <f:param name="quantity" value="#{product.quantity}" />
</h:commandButton>

请注意,这些参数不会出现在请求URL中(如您在浏览器地址栏中看到的那样),并且您的理论方法也不会这样做,因此JSF命令按钮即会生成HTML <input type="submit">提交到与父HTML <form method="post">action属性中指定的URL完全相同的URL的元素.

Note that those parameters don't end up in the request URL (as you see in the browser address bar) and that your theoretical approach also wouldn't have done that, a JSF command button namely generates a HTML <input type="submit"> element which submits to the very same URL as specified in the action attribute of the parent HTML <form method="post">.

还请注意,这些参数不在表单提交期间评估,而是在显示表单期间评估.如果您打算以这种方式传递提交的值,那么您基本上就是在做错了.也许您想将它们指定为视图参数,以便可以将action="editOrDeletePage?faces-redirect=true&amp;includeViewParams=true"用作操作.

Also note that those parameters are not evaluated during the form submit, but during displaying the form. If you intented to pass submitted values along that way, then you're basically doing it wrong. Perhaps you want to specify them as view parameters so that you can use action="editOrDeletePage?faces-redirect=true&amp;includeViewParams=true" as action.

毕竟,由于您根本没有详细阐述具体的功能要求,因此很难为您提供正确的解决方案.

After all, it's hard to propose the right solution for you as you didn't elaborate the concrete functional requirement in detail at all.

这篇关于在JSF中不是有效的方法表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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