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 Passing a bean value from a onclick javascript call. 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 "Passing a bean value from a onclick javascript call." Watch "Passing a bean value from a onclick javascript call." New topic
Author

Passing a bean value from a onclick javascript call.

Nagendra Shastry
Greenhorn

Joined: Oct 26, 2010
Posts: 19
Hi All,

I have a richmodalpanel which contains a richpicklist. In the same panel I have a button. My requirement is onclick of the button, ID of the selected items from richpicklist should be sent as parameter to a javascript method. I tried doing with zero result. Can you people please help me?

My code is :




Here on click of Save button, I am calling updateLOB(selectedDistType) which is a javascript method. But the parameter value is coming as null.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15962
    
  19

Two things that would help us provide an answer:

1. Use the "Code" button to wrap tags around your sample code and XML to make them easier to read.

2. Remove everything that doesn't actually have to do with what you are trying to get working from your samples. Otherwise the forest obscures the trees, so to speak.

From what I was able to read, I can see possible trouble in one case, for certain. The "onclick" code for a h:commandButton or its AJAX-enabled a4j:commandButton equivalent MUST return either true or false. If it returns TRUE, the form (or selected parts of the form for a4j version) will be submitted to the server. If it returns FALSE, the submit is suppressed.


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

Joined: Oct 26, 2010
Posts: 19

Hi Tim,

I have wrapped using code now. Here I want to pass the selected id's of rich:picklist as parameter in onclick ="uploadLOB('param')" . I am unable to get the id's. I googled a lot how to get the id's and pass it onto javascript method but with no result.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15962
    
  19

One thing I've learned from JavaScript is that I hate JavaScript. Even with jQuery helping, it causes more trouble than it's worth.

For myself, what I would probably be doing here is that I would get rid of the javascript, bind the button to an ajax listener method with partial form submit (ajaxsingle=true), and let the backing bean handle it.

When I do do stuff like this in JavaScript, I generally try to push all the actual nastiness out to a javascript element. Then I'll pass the control that I'm going to act on as a parameter to that script. Like so:


I've probably got the RichFaces version of getElementById mangled since I'm using what passes for my memory.

I do NOT recommend what you did to set up the selectItems. You would be better off changing it to a value reference instead of a function call. What I normally do when I need a list of selectItems built for me is have the property "get" method check for a cached copy of the list and call the list constructor if there wasn't one. This is handly because I can refresh the list by simply invalidating the cached list.
 
Consider Paul's rocket mass heater.
 
subject: Passing a bean value from a onclick javascript call.
 
Similar Threads
label value in servlet
retrieve check box value rendered dynamically by a javascript
How to getParameter value
f:ajax calls causing malformedXML error in IE9
Doubts in jsp