• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

setting a session variable at the top of a jsf

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 90
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 26017
186
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ruth Stout was famous for gardening naked. Just like this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic