• Post Reply Bookmark Topic Watch Topic
  • New Topic

setting a session variable at the top of a jsf  RSS feed

 
Christopher Whu
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there anyway to set a session variable from within a JSF page?

On jsp i would just add
session.setAttribute("chosenProduct", "foo");

Is there an equivalent way to do this in jsf?

i would like to set the variable and then build my datatable(from a backing bean fed a variable) all with one page if possible...

my backing bean is using
@Named
@SessionScoped
 
Cesar Loachamin
Ranch Hand
Posts: 90
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Christopher

You can set the session attribute in the backing bean in a action listener for example:


And from the jsf page you can get the value of the session atribute with the value expression


Hope this helps you with what you need

Regards,
Cesar
 
Tim Holloway
Bartender
Posts: 18663
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't do that even on a JSP. It's polluting the separation of concerns in MVC, and I've seen some pretty polluted JSPs.

When I want to pre-configure editing of a database object in a JSF page, I normally am coming from some other JSF page. Which means that I'm using an action method. In that action method I typically invoke a "beginEdit" method that allows me to pass in the object (or key of the object) that I'm going to edit and do the required setup work before the edit page is displayed.

To make this work, you have to inject the editing backing bean into the calling backing bean, since the beginEdit method is part of the editing backing bean.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!