简体   繁体   中英

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?

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"/>

I believe that the problem is the scope of the bean - request. Do you load the data after each request? If not then its pretty clear that values are null. Try session scope or you would have to get data from your service or elswere..

Edit:

Post here the code of your controller, without it I cant be much help. This problem can be solved without putting bean into session scope. In short: you need to use gettres and setters to store your data in bean properties between the requests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM