Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

storing mbs on session doubt  RSS feed

 
Rafael Fagundes
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all.

Well I�m starting to work with JSF and I�m developing a system that have pages with some fields (like inputText) to store on db. This pages also contains dataTables to show what�s on the respective db table. The user can make insert, update, query and delete operations with these pages. I found out that if I store witch respective mb on the session it�s easier to work (easier than work with request mb). But at the same time I�ve noted that this approche requires a lot of the server (memory) and the state of witch page remains the same (I�m trying to figure out how to clean the session).

My doubt is: should I stop to work whit the sessin like I�m doing? Is this a common approche? Or should I work with request mbs and use hidden fields to controll the user operations?

Thank�s for your attention,
Rafael.

PS: Sorry for my bad english! ;)
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and the state of witch page remains the same

you mean that if you goto the page again, its prepopulated with the previous values?

Here is a trick that has worked for me. Whenever I use a managed bean with session scope in a page (and I want it to clean it up), I put this as the first line in my jsp.

<h:panelGrid rendered="#{employeeBean.prepare}" />

where employeeBean is my managed Bean.

And I have a getPrepare() method in my managed bean that initializes all the instance variables (clean up).
 
Rafael Fagundes
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lynette. Thank's for your reply....... it really helped.
 
Tim Holloway
Bartender
Posts: 18709
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oooh, that's kludgy! :shocked:

I think I'd try really hard to make that stuff live in a managed Request-scope bean. You can then inject a session bean into the request-scope bean to handle the session-related stuff if it needs it.

Just a reminder, BTW for those who didn't know: You can reference as many different beans in as many different scopes as you like on a JSF page. You don't have to have one and only one bean!
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Tim said: +1.

My way of handling most session data is to ecapsolate all the objects I need available in the session into a single object and just place that object into session. Then I always know what my session object is called and I have all the appropriate getter/setter methods I need.

And I'll usually inject that object into any of my managed beans that I think might need it.
 
Rafael Fagundes
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, thank�s Tim and Gregg. I�ll make a refactor on these components that I mentionated above to get the best solution as possible!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!