• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Setting value to property of managed bean from javascript

 
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
 
Ranch Hand
Posts: 101
Spring Flex Java
  • 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";
 
Saloon Keeper
Posts: 22483
151
Android Eclipse IDE Tomcat Server Redhat Java 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
 
Proudly marching to the beat of a different kettle of fish... while reading this tiny ad
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic