• Post Reply Bookmark Topic Watch Topic
  • New Topic

Scope in JSF

 
Tushar Kherde
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All Ranchiens,
I am having page in jsf where the scope is request. In the bean of that page i am using one list whose scope is also request as the bean's scope is request. I want the list's scope to session but i want to keep the same request scope for bean. Is it possible if yes how? Please help me out.
Please let me know if anything else is needed.
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not the page that has a scope, it's the bean itself. A page can contain beans that have page, request, session or application scopes in any mixture, but each bean has exactly one scope.

Scope is what determines how long the bean lives.
 
Tushar Kherde
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok i got it, but if i m having a some datastucture in a bean e.g. List what will b the scope of it. is it the same as bean or is it independent of bean. can i set differnt scope for it in jsf bcoz i think we dont explicitly handle request object in jsf, right? if i am wrong pls correct me
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tushar Kherde:
but if i m having a some datastucture in a bean e.g. List what will b the scope of it. is it the same as bean or is it independent of bean.


It would be in the same scope as bean.


Can i set differnt scope for it in jsf bcoz i think we dont explicitly handle request object in jsf, right? if i am wrong pls correct me


Couldn't get you by this. What are you trying to do?
 
Dhananjay Inamdar
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tushar,

You can keep your been in request scope only.
In your bean code where you want to add a perticular list to Session scope there you can write following code.

//At first get FacesContext
FacesContext.getExternalContext().getSessionMap();

Then you can bind your list to a session with some variable using SessionMap.

Cheers
 
Tushar Kherde
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dhananjay

i tried following code. its working perfectly. where "dataScheduleList" is the List which i want to store into session.

FacesContext context = FacesContext.getCurrentInstance();
HttpSession session=(HttpSession)context.getExternalContext().getSession(false);
session.setAttribute("dateScheduleList",dateScheduleList);
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!