4

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}"/>

I can get it to work if I only have

action="editOrDeletePage.xhtml?editing=true"

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

4

2 回答 2

9

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.

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>

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">.

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.

于 2012-12-16T01:17:42.117 回答
0

If you are using JSF2 you can use h:button for this

<h:button value="press here" outcome="editOrDeletePage">
    <f:param name="productId" value="#{product.id}" />
</h:button>
于 2012-12-16T00:33:03.537 回答