How to save f: viewParam values โ€‹โ€‹after postback with check completion

I have an xhtml page with a simple form. This page is used for multiple data tables. To specify a data table (etc.), I use GET request parameters. xhtml page gets it through

<f:metadata> <f:viewParam id="page" name="page" value="#{itemsBean.page}"/> </f:metadata> 

and again go to the navigation rules for example

  <navigation-case> <description> Global rule for going to the items page from any page </description> <from-outcome>items</from-outcome> <to-view-id>/items.xhtml</to-view-id> <redirect> <view-param> <name>page</name> <value>#{itemsBean.page}</value> </view-param> </redirect> </navigation-case> 

But if I use the inputs in the xhtml file, for example,

  <h:inputText id="itemName" value="#{itemsBean.name}" required="true" requiredMessage="Value for this field required!"/> 

I cannot restore the view parameter after trying to take the form without entering text. I tried using hidden input to pass parameters

 <h:inputHidden id="page" value="#{itemsBean.page}" /> 

but it looks like the check is done before and itemsBean.page is still empty. itemsBean is requested. What am I doing wrong? How to pass a parameter?

Thanks for your time.

+4
source share
1 answer

You need to save the query parameters for a subsequent query. In "plain vanilla" HTML, you would really use <input type="hidden"> for this, but JSF <h:inputHidden> , unfortunately, doesn't work that way. In the event of a general verification failure caused by another input field, the model value associated with <h:inputHidden> will not be updated at all.

Instead of <f:param> in UICommand , use <f:param> to save the request parameters for a subsequent request. For instance.

 <h:commandButton ...> <f:param name="page" value="#{param.page}" /> </h:commandButton> 

Alternatively, you can use the <o:form> OmniFaces JSF utility library , it basically extends <h:form> with the optional includeViewParams attribute, which allows you to save the presentation parameters for later request in the form URL.

 <o:form includeViewParams="true"> ... </o:form> 

This may turn out to be easier if you have several buttons / links to commands and ajax actions, and this will be the only way if you want to keep the same URL during inactive postbacks.

+3
source

Source: https://habr.com/ru/post/1432892/


All Articles