1

The page starts with two selectManyListBoxes. The one on the right starts out empty. I then move items to the right with javascript. When I submit the form javascript selects all items in the listBox on the right before submission. JSF fails validation because there are now items being submitted that weren't originally there.

So my hacky solution is to have a hidden input on the page. Upon form submission have the javascript put all items that are in the right listBox in that hidden input and deselect all items in both listBoxes. So, I'm basically hacking past JSF's security feature.

My question: Is there a better/more official/sanctioned way of doing this? I'm sure it's done all the time. Seems like a pretty common feature.

rlb.usa
  • 14,942
  • 16
  • 80
  • 128
Dale
  • 1,289
  • 3
  • 16
  • 36

1 Answers1

1

Move the items by JSF instead of JS. So remove all those JS functions and replace them by JSF action methods. If you aren't on JSF 2.0 yet which offers <f:ajax> tag for better user experience, then I suggest to look for a 3rd party component library which offers Ajax capabilities or even supports a whole single component for it. For example RichFaces has a <rich:pickList> for exactly this purpose. Otherwise you have to use two <h:selectManyListbox> components with a bunch of command buttons to move the one to the other.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I forgot to say I'm using JSF 1.2. So when you say, "replace them by JSF action methods" do you mean send the info back to the server and have the listBoxes refreshed by the server? I see my options as being... do it how I'm doing it, use richfaces, use JSF action methods. So knowing that I am using JSF 1.2, what would you recommend? – Dale Nov 21 '11 at 18:39
  • Are you using any ajax component library? If not, you'd consider looking for one. You could if necessary just stick to standard JSF components like `` and add ajax enhancements with help of for example `` (part of RichFaces) and so on, instead of replacing the entire component by a single component. – BalusC Nov 21 '11 at 18:44
  • I was hoping for a solution that didn't require further hits to the server. I'm getting the feeling it's do it how I'm doing it or hit the server. – Dale Nov 21 '11 at 19:09
  • No, with a server side component based MVC framework, you've got to notify the server side about changes to the view in the client side. Just don't use JSF if you all you want is more fine grained HTML/CSS/JS control. Or if all you want is no code boilerplate, then just pick a JSF component libary which offers the components you need. See also: http://stackoverflow.com/questions/4421839/what-is-the-need-of-jsf-when-ui-can-be-achieved-from-css-html-javascript-jquery – BalusC Nov 21 '11 at 19:12