posted 10 years ago
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.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.