Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not A Valid Method Expression in JSF

Tags:

jsf

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?

like image 200
user1154644 Avatar asked Jan 14 '23 18:01

user1154644


1 Answers

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.

like image 66
BalusC Avatar answered Jan 31 '23 08:01

BalusC