tags:

views:

143

answers:

1

I am a beginner in JSF. I am building an application where on loggin on user details from the database are to be displayed in another JSP. I use a managed bean each for all of my jsp pages (JSF) I have defined thier scope as request in my faces-config XML. On logging in the details are verified by an actionListener method in my login page. Before leaving this method I am attempting to set attributes of the managed bean of the next page. But the state that I have set is not preserved in the second page. What am I missing out.

P.S. Please redirect me if this question was asked before and answered.

Thank you

+1  A: 

The boundary between the two requests is when you return the navigation outcome from your managed bean action. Then a redirect (if configured so) is triggered to that outcome.

You have three options:

  • don't use <redirect /> in your nagivation rules - thus you'll stay within the same request even when you show another page after submit. The downside is that this hurts user experience - if refresh is pressed, the ugly 'resubmit' dialog appears
  • use session scope - this is not harmful in small doses, but be careful not to have too many session-scoped beans.
  • use a conversation framework (like MyFaces Orchestra) - defines a custom scope called "conversation.access" - your data is accessible as long as it is needed.
  • use <a4j:keepAlive> from richfaces - preferred for ajax-requests.
Bozho
I am more likely going to explore the third option for it seems to be a solution to problems that may arise later on. Thanks and can you also tell me where the in the execution the normal request scope ends?
Ashwin Kumar
yes, updated my answer. (btw, whenever an answer is satisfactory for you, stackoverflow mandates that it should be "accepted" - the the tick below the vote counter)
Bozho
Thanks again. I hadn't known bout the accepting answers bit. Sorry. Have done that now.
Ashwin Kumar