aspose file tools*
The moose likes JSF and the fly likes Keep bean properties between requests Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Keep bean properties between requests" Watch "Keep bean properties between requests" New topic
Author

Keep bean properties between requests

Dmytro Kostiuchenko
Greenhorn

Joined: Nov 02, 2010
Posts: 3
I have 2 pages: one shows list of users in datatable, say listusers.jsp, another — user's details and it's activities on some date (in datatable too), say viewuser.jsp.
The second page is backed by viewUserBean, which has properties currentUserId, currentDayId.
To come from listusers.jsp to viewuser.jsp I do the next thing


Then on viewuser.jsp I want to select a day of activity, and I do this


The backed bean is in request scope, and I believe, it should be there. But the problem is that it's currentUserId property isn't persist between requests. So if I select some plan, page will be redisplayed as I've passed currentUserId = null to it.

How to keep currentUserId property of the backed bean, which is in request scope between requests?
Thanks.
B Nirvan
Ranch Hand

Joined: Oct 20, 2010
Posts: 82
If your current userId is bound to hutputText in your viewUser.jsp, then it won't get back to your viewUserBean during request submit and the value will be lost. It seems that you are just displaying the UserId in viewuser.jsp and hence it is not persisting between requests. I could see a couple of approaches to this problem

You can store the userId as a session attribute and then retrieve it for the next request from your viewUserBean. This would need some additional code in your bean.

If you are using JSF 2.0 or higher, your viewuserbean is a very good candidate for @ViewScoped Bean. The bean stays as long as you are on the same page, that is on viewuser.jsp. Once you are done with viewuser.jsp and navigate to some other page of your application the bean will go out of scope.

regards,
Nirvan.
Dmytro Kostiuchenko
Greenhorn

Joined: Nov 02, 2010
Posts: 3
Thank you for reply.

Seems, like session scope is my the only choise.

I'm using Spring for managing JSF beans, and so I can't declare my bean to be in view scope in a simple way. I have to implement such scope at first, that is not a simple task for at the moment. Anyway, thanks for this info, I didn't know about this scope type.

Maybe recreating bean property is possible with hidden input?
I've tried to play with it already, but it didn't work for me.
Dmytro Kostiuchenko
Greenhorn

Joined: Nov 02, 2010
Posts: 3
I've solved this problem declaring bean in view scope and implementing custom scope for Spring
http://cagataycivici.wordpress.com/2010/02/17/port-jsf-2-0s-viewscope-to-spring-3-0/

Thanks once more, Nirvan Buddha for telling me about view scope.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Keep bean properties between requests