开发者

JSF + richfaces problems after submit

I need to ma开发者_如何学JAVAke 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜