• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Passing a bean value from a onclick javascript call.

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Nagendra Shastry
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic