aspose file tools*
The moose likes JSF and the fly likes Why is @SessionScoped bean reinstantiated ? 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 "Why is @SessionScoped bean reinstantiated ?" Watch "Why is @SessionScoped bean reinstantiated ?" New topic
Author

Why is @SessionScoped bean reinstantiated ?

Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Hello!

I have really strange misunderstanding.

Description:

When I click 'Login' link (located in template) I submit form by executing the action method which determines current page. Action method returns 'pretty:login'
for the following prettyfaces mapping:

As a result my url ends by '/login' which causes embedded JavaEE security system to intercept this url.

Problem:

After I fill in login form and click 'Login' button I am not redirected to '/forums.jsf' and even pretty method user.redirectLoggedInUser is not called at all !!!
Login button is simplest: <input class="loginSubmit" value="Login" type="submit" title="Click to login!" />
Very strange is that my main @SessionScoped bean is instantiated again(it is logged that @PostConstruct is called) and I am redirected to my home page.
Why is that?

Thank you!


True person is moral, false is right!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16141
    
  21

Any time a session-scope Managed Bean is referenced via EL and it does not exist, it will be created on-demand. I don't really know what destroyed your original session object unless you had done a session.invalidate() somewhere.

When using container-managed security, Login is handled on-demand, so setting up an action to explicitly "go to login" isn't how it is done. In fact, you cannot "go to login", since the login screen has no functional URL to go to.

All that is necessary is that you request a secured URL. So if forums.jsf is a secured URL, the source action should request forums.jsf and login will be handled automatically, if needed. Because this is JSF, you need to include the redirect directive on the source navigation, though, or the requested URL won't be pointing to forums.jsf because of JSF's URL lag.


Customer surveys are for companies who didn't pay proper attention to begin with.
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Sorry problem is resolved already.

I prohibited my browser to accept cookies for my localhost and it caused many stupid, ridiculous problems!

Everything is OK so far!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why is @SessionScoped bean reinstantiated ?