Reputation: 29
I would like to set a parameter in the url via post but this page only perform a method and update the page with h: commandButton.
<h:commandButton value="Simular"
action="#{simulador.simular()}"
style="margin:0 4px 0 0;"
immediate="true">
<f:ajax render="@form" immediate="true"/>
</h:commandButton>
How can I achieve this?
Upvotes: 2
Views: 1799
Reputation: 1109072
URLs are only changed on synchronous requests. Adding a query string to URL is only possible on GET requests. Sending a redirect after POST is one way to create a synchronous GET request.
public String simular() {
// ...
return "page.xhtml?foo=42&faces-redirect=true";
}
This will redirect to /context/page.xhtml?foo=42
.
If you actually don't need to perform any business logic in the action method based on the postback, then you can also just use a normal button instead of a command button.
<h:button value="Simular" outcome="page.xhtml">
<f:param name="foo" value="42" />
</h:button>
Upvotes: 2