By default, your code (and especially your <h:form>
tag) generates the following HTML output:
<form id="form" name="form" method="post" action="/yourApp/yourPage.xhtml" enctype="application/x-www-form-urlencoded">
<input type="submit" name="j..." value="Ajax Submit" />
<input id="javax.faces.ViewState" ... />
</form>
Note that the action
of the generated <form>
element is the current view id without any get parameters attached to it, despite the initial page could have had them. Thus, they are not set on form submit as well.
To handle the situation you can:
- Use a
@ViewScoped
bean holding the values of those parameters upon initial access; - Add some hidden input fields to your form so that they are sent upon form submit as well or nest
<f:param>
inside your<h:commandButton>
; - Use OmniFaces'
<o:form includeViewParams="true">
tag (Tag documentation / Showcase example) instead of the<h:form>
, as it will submit to the current URL with view parameters attached, provided they were set using<f:viewParam>
(see, for example, BalusC's answer to Retain original GET request parameters across postbacks for details).