Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Updating session value in JSF2  RSS feed

 
raj reddy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using JSF2 with Primefaces. Here is my business requirement-Hidden field on JSF page should take the value from the session object that is set in managed bean. Session object is updated every time when the user submits the page.
I am able to update the session object in the managed bean and able to get the value in the hidden field first time and after that i see the same value in the hidden field even though session object has different value.
I would appreciate if someone helps me if i missed anything. Here is the hidden field: <h:inputHidden id="xyz" value="xyz"/> i tried using sessionScope but still didn't work.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There doesn't seem to be much point in writing a session value out to a page just to read it back in again. The session object on the server isn't going to change unless some other page request updates it.

Regardless, a hidden-text control is handled in JSF exactly like the inputText control is. Meaning that the built-in Controllers in JSF will automatically post out the current property value when rendering the page and will automatically update the backing bean from that control when a request is made for the form that contains that control. There's no special user code required.
 
raj reddy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're right but my user requirement is like this... When the user working on multiple tabs and close the tab that is authenticated and then opens another tab, he should be prompted for authentication. Is there any way to implement this?
I am updating session object every time it invokes filter but hidden field not getting updated...
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you mean browser tabs, it's pointless. Every window and tab belonging to a web browser program shares the same session. There isn't a separate session for each tab. Though JSF is not very friendly to multi-window or multi-tab web applications (neither am I, actually, but that's another matter).

Also, if you're using user-designed authentication/authorization code, I don't recommend that anyway. Such things are rarely even a fraction as secure as their designers think they are. J2EE has a pre-debugged well-defined system built in for that, and it works well with JSF.
 
raj reddy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick reply. You're right, session is shared across all tabs on the browser but its weird client requirement. We're using Sitemider for authentication/Authorization purpose. I will try to implement some ugly code to prevent this issue..
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ugly code is fragile code, and fragile code is expensive.

You can use SiteMinder as part of the standard Java security subsystem, at least when you're using the Tomcat server. I'm not familiar with the details, but Google is.
 
raj reddy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim, I am trying to update hidden field value on jsf from the bean but couldn't success. Is there a way to update the value? Appreciate if you could assist on this.
Here is my code: <h:inputHidden id="a" value="#{xyz.ab}">
ab is getter method from the bean. Ist time i see the value and subsequent updates, i don't see updated value (value remains the same) even though value changes in the bean.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure how you mean "update".

JSF will automatically update the backing bean from an input control when a form is submitted. It will automatically update the (invisible) display when the page is displayed or re-displayed in response to a submit or URL request. Or, in the case of AJAX, when the AJAX request indicates that the control or one of its parents is to be re-rendered in response to the AJAX request.

If you're hoping to update the page based on changes made in some other page, however, that's not possible using HTTP.

In the HTTP protocol, which is what JSF is built on, you send down one request and you get back one response from it. So one and only one tab or window will be updated per submit and the other tabs/windows will remain unchanged.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!