• Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting value to property of managed bean from javascript  RSS feed

 
Praveen Yendluri
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone,

I am opening a pop-up in jsf page. The pop contains normal html Close button. Clicking on this button should go to javascript function and in this function it has to set value to property of managed bean.

Ex: setIsGlobal(boolean isGlobal)

I need set value to above mathod in managed bean to false.

Requesting you to help me on this?

Thanks,
Praveen
 
Shasi Mitra
Ranch Hand
Posts: 101
Flex Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can have a hidden textbox bound to a bean property and set the value to the hidden textbox in the javascript.

eg: <h:inputHidden id="yyy" value=#{bean.global}"/>

In javascript method : document.getElementById('yyy').value="sdfsdfs";
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're popping up a new window,

I hate popup windows passionately. My browser is set top open new windows as tabs because I've got enough windows littering my screen without multiple browser windows adding to the confusion. Plus (more practically), anything you do in the popup window won't be reflected in the parent window unless you explicitly refresh the parent window.

If you want JavaScript to modify a backing bean property, you'll have to submit a request to the server to POST the form that contains the updated value. In the case you described, that probably means that you'll have to create a (possibly hidden) JSF component that the "close" script updates before it submits the actual POST. Basically, what Shasi suggested, but with the added correction that the true ID of a JSF component from JavaScript's viewpoint isn't just the control's "id=" attribute, but a concatenation of the control's ID and its parent ID(s).

Submitting a JSF POST from JavaScript is not a trivial task, so it's best if you use AJAX.
 
Praveen Yendluri
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you vey much guys for your response.

I have used Ajax to set bean property.

Thanks,
Praveen
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!