• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ViewScoped bean using ManagedProperty

 
Ilari Moilanen
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a managed property inside a view scoped managed bean like this:where the LoginUser is a session scoped managed bean.

But the loginUser is always null! Why?

When I use the same syntax with request scoped or session scoped beans JSF injects automatically the loginUser where I want. So for example this does work: In addition I know that the loginUser is not actually null since I can access it from the ViewScoped bean with this codeI do not see where the problem is. ViewScoped is considered to be between RequestScoped and SessionScoped so it should not be a "visibility" problem (I mean that for example SessionScoped managed bean can not use RequestScoped managed property since the property is changed in every request).

I'm using MyFaces 2.0.1 so maybe there is a bug in MyFaces? Any thoughts?
 
Brendan Healey
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, is #{loginUser} a pre-defined FacesContext property in MyFaces? it's not in Mojarra as
far as I know. Anyway, I had inconsistency problems when using @ManagedProperty in
Mojarra and reverted to the long hand (for example):

FacesContext.getCurrentInstance().getExternalContext().getLoginUser()

Whilst a bit out of my depth I thought I'd make the suggestion. Good luck with it.

Regards,
Brendan.
 
Ilari Moilanen
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
#{loginUser} is a simple managed bean (related to custom login procedure) as I stated above. But when I did some rechecks on this problem now I realized that the actual problem is not only the @ViewScoped bean.
When I check the presence of loginUser normally then it is present no matter if the calling bean is @RequestScoped, @SessionScoped or @ViewScoped. But when I use AJAX call (with f:ajax) then the loginUser is not present if the calling bean is @ViewScoped. This looks like a bug in the implementation of @ViewScoped. And the bug may be only present in the implementation that I use (MyFaces 2.0.1 and 2.0.2).

I may check if the behavior is changed when using the Mojarra implementation...

EDIT: I tested it and for some reason I can not get Mojarra implementation (2.0.1) do the ajax call at all. I do not have time to find what the reason is so this problem remains unresolved.

EDIT2: Argh, tested this with Mojarra 2.0.3 and the ajax call worked but the loginUser remains as null (although it is in the session). So this may be intended for some reason. Can not understand what the reason might be but nevertheless...
 
Joe Shannow
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ilari Moilanen wrote:#{loginUser} is a simple managed bean (related to custom login procedure) as I stated above. But when I did some rechecks on this problem now I realized that the actual problem is not only the @ViewScoped bean.
When I check the presence of loginUser normally then it is present no matter if the calling bean is @RequestScoped, @SessionScoped or @ViewScoped. But when I use AJAX call (with f:ajax) then the loginUser is not present if the calling bean is @ViewScoped. This looks like a bug in the implementation of @ViewScoped. And the bug may be only present in the implementation that I use (MyFaces 2.0.1 and 2.0.2).

I may check if the behavior is changed when using the Mojarra implementation...

EDIT: I tested it and for some reason I can not get Mojarra implementation (2.0.1) do the ajax call at all. I do not have time to find what the reason is so this problem remains unresolved.

EDIT2: Argh, tested this with Mojarra 2.0.3 and the ajax call worked but the loginUser remains as null (although it is in the session). So this may be intended for some reason. Can not understand what the reason might be but nevertheless...


Did you find the solution? I have exactly the same problem.. @ManagedProperty is working fine, ajax doesn't (object is null)
 
Ilari Moilanen
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alas, I did not find a solution to this problem.

My workaroud is as follows
So I put the check to the normal getter. I just have to remember to use the getter and never the object directly (since the first time it is null).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic