• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Keep bean properties between requests

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your current userId is bound to h:outputText 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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic