• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why is @SessionScoped bean reinstantiated ?

 
Volodymyr Lysenko
Ranch Hand
Posts: 512
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Volodymyr Lysenko
Ranch Hand
Posts: 512
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic