Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to get sessionScope variable value in javascript

 
srikanth Thandra
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18014
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Cesar Loachamin
Ranch Hand
Posts: 90
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
srikanth Thandra
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 90
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic