I want to create JSF registration form which has select menu with the list of all countries. I know that this is easy for implementation with Java HashMap but the tricky part that I don’t know how to implement is how right after the user selects his country from the list, second select menu to appear with the cities in his country? Is there any useful example?
Best wishes.
You can use
<f:ajax>for this. When nested in an input component such as<h:selectOneMenu>, then it will by default be invoked when the input value is changed. You can specify alistenermethod which could prepopulate the data for the next component based on the current input value, and you can specify the client ID of that next component inrenderin order to show the prepopulated data.The bean must be in at least the view scope (not request):
You can of course also use a
Map<String, String>instead of aList<String>. The map key becomes the option label and the map value becomes the option value. You only need to keep in mind that aHashMapis by nature unordered. You’d prefer usingLinkedHashMapinstead to display the items inMapinsertion order.See also:
selectOneMenuwiki page