Search code examples
jsfrichfacessubmit

JSF + richfaces problems after submit


I need to make a search page for some project. Input fields are:

<h:inputText styleClass="field35" value="#{searchBean.country}"></h:inputText>
<h:inputText maxlength="20" styleClass="field35" value="#{searchBean.destination}"></h:inputText>
<rich:calendar  datePattern="dd/MM/yyyy" value="#{searchBean.startDate}"></rich:calendar>
<rich:calendar  datePattern="dd/MM/yyyy" value="#{searchBean.endDate}"></rich:calendar>

and after I press:

<h:commandButton id="cb41" action="#{searchBean.processForm}" value="Search" styleClass="button" />

I expect results to be printed in the rich:dataTable section on same page.

<rich:dataTable value="#{searchBean.results}" var="journey">

In the processForm method the results variable is populated with data from database and user is forwarded to the same page.

Everything is fine after the first search, but when I press search again bindings between bean and page input fields are lost. In other words, in processForm method for country, destination, startData and endDate I get only nulls, no matter what is in the corresponding fields on the page.

The scope of the bean is request and all fields have getters and setters.

Does anyone have an idea what might be the problem?

Thanks.

Edit: thanks t-edd Changing scope to session worked, but that is a bit of a performance killer to keep entire bean in the session all the time (and complicated to delete it every time I leave wanted page). I understand why the bean is destroyed, but shouldn't a new one be created after the next request with proper values from me page?


Solution

  • it seems you need to add

    <t:saveState value="#{searchBean}" /> 
    

    to your page.

    this controller saves the state of your bean between requests (it provides the ability to store a model value inside the view's component tree. ).

    that way its data will be saved without the need to change the scope of the bean to session (which i do not recommend)

    you can also use

    <a4j:keepAlive beanName="searchBean"/>