This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSF and the fly likes how to get sessionScope variable value in javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "how to get sessionScope variable value in javascript" Watch "how to get sessionScope variable value in javascript" New topic
Author

how to get sessionScope variable value in javascript

srikanth Thandra
Ranch Hand

Joined: Mar 04, 2009
Posts: 42

hi,

I am setting a childCount property of type integer in backing bean into session using



how to retrieve the above sessionScope variable value in javascript.

I am using xhtml,jsf1.2,facelets


Thanx in advance,
Srikanth
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15960
    
  19

JavaScript operates in the client. Session Scope variables reside on the server. Therefore, to get the value, you must make the client petition the server for the property value you are interesting in. That requires that you create some AJAX code on the client or make the property value part of the original view request (it can be an invisible form field).


Customer surveys are for companies who didn't pay proper attention to begin with.
Cesar Loachamin
Ranch Hand

Joined: Dec 25, 2010
Posts: 90

Hi srikanth

You can do the option of Tim wich is very practical or you can use the expression languange in javascript, here a example how you can solve your problem.
It works for me.

Regards

Cesar


When a dream is ending because to come true - OCPJP 6,7. OCE JPA EE6. MCTS
srikanth Thandra
Ranch Hand

Joined: Mar 04, 2009
Posts: 42

hi Cesar Loachamin,

I checked with your example code of what you have given.

It doesn't working. See below what i have done:

Cesar Loachamin
Ranch Hand

Joined: Dec 25, 2010
Posts: 90

Hi Srikanth

This is because the DHMTL event onclick is fired before the actionListener, if you click again in the button you can see with the alert(); the right value. You need to set up the value of childNumbers in the session before the call of the javascript function setChildCountValue().
One observation when you're using EL in javascript you must put it between a quotes.
Regards
Cesar
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to get sessionScope variable value in javascript
 
Similar Threads
Setting a Boolean SessionScope Variable
Setting a Boolean SessionScope Variable
RAD 7.0 JSF sessionScope variable, how to set default value?
<h:outputFormat displaying null values on page load
Doubt in EL [] operator