aspose file tools
The moose likes JSF and the fly likes Setting value to property of managed bean from javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Setting value to property of managed bean from javascript" Watch "Setting value to property of managed bean from javascript" New topic
Author

Setting value to property of managed bean from javascript

Praveen Yendluri
Greenhorn

Joined: Apr 13, 2011
Posts: 27
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

Joined: Nov 27, 2008
Posts: 101

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
Saloon Keeper

Joined: Jun 25, 2001
Posts: 14456
    
    7

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Praveen Yendluri
Greenhorn

Joined: Apr 13, 2011
Posts: 27
Thank you vey much guys for your response.

I have used Ajax to set bean property.

Thanks,
Praveen
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting value to property of managed bean from javascript
 
Similar Threads
JSF read GET Parameters into Backing Bean
PropertyNotFoundException: Can't set managed bean property
Setting Values for Bean Properties
Accessing jsf bean from another jsf bean
Problem with initializing managed-property parameter