This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Dropdown populating dropdown  RSS feed

 
Kevin Galligan
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I imagine this is a pretty basic deal. I've been doing light jsf on and off for quite some time, but not any real projects. Finally I'm starting one. I beat myself up on day one. Here's the deal.

Filling in an address. Two fields. A country dropdown, which should drive the population of a state dropdown. In a perfect world this could be an ajax style affair, and before there was "ajax" I've done this kind of thing in struts and pojsp (Plain Old Jsp. First use I've ever seen of that, and probably because it isn't really pronouncable). However, for today, I'm willing to keep it basic and do the page refresh.

So, is there a good page one can point me to on how this should be done? I left it off with the following:

Country dropdown with a value change listener applied. This listener populates the list of SelectItem values for the state dropdown on the backing bean. The country dropdown has an 'onchange="submit()"' on it and 'immediate' set to true.

It took a while to get all of that sorted out. And, crazy enough, it worked. That was pretty sweet. Of course, it all fell apart when I clicked the regular submit button and had a validation error. Because my backing bean is in request scope, the List populated by the listener no longer has values.

So, on the train in today, I thought of what would work better.

Bind the country dropdown to a field in the backing bean. The method that gets the state List will just look at that UI component's value to figure out which country to use. The value change listener on the dropdown will just send the request directly into render response. This should also work on a normal submit.

Any thoughts?
 
Kevin Galligan
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, anybody have a link to a good example for this kind of thing? One dropdown selection populating another?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!