2

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?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 1
    In order to inject a parameter in the url you should perform a complete postback instead of ajax. There's also a way to do that using javascript to get bookmarkable urls. What are you exactly trying to achieve? – Aritz Apr 22 '13 at 16:07
  • 1
    @Xtreme: your first statement is not correct. – BalusC Apr 23 '13 at 12:45

1 Answers1

2

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>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555