Netbeans Autosubmit Drop Down Boxes
Tuesday, March 27th, 2007The immediate attribute against the dropdown box is a bit misleading. This is wholly different from the autopostback=”true” attribute on ASP.net.
With JSF, you need to write your own javascript, or use the IDE context menu to write one for you.
Here’s a code sample showing how to change the contents of a second dropdown box based on the value of the first one.
public void dropDown1_processValueChange(ValueChangeEvent event) {
String newValue = (String) event.getNewValue();
java.util.ArrayList options = new java.util.ArrayList();
if (newValue.equals("Australia"))
{
options.add(new Option("Sydney"));
options.add(new Option("Canberra"));
options.add(new Option("Brisbane"));
options.add(new Option("Perth"));
options.add(new Option("Melbourne"));
} else if (newValue.equals("US")) {
options.add(new Option("Washington"));
options.add(new Option("New York"));
options.add(new Option("Los Angeles"));
} else if (newValue.equals("Japan")) {
options.add(new Option("Tokyo"));
options.add(new Option("Saitama"));
options.add(new Option("Niigata"));
}
int size = options.size();
Option[] optarr = new Option[size];
options.toArray(optarr);
dropDown2DefaultOptions.setOptions(optarr);
}