/* * Smart GWT (GWT for SmartClient) * Copyright 2008 and beyond, Isomorphic Software, Inc. * * Smart GWT is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3 * as published by the Free Software Foundation. Smart GWT is also * available under typical commercial license terms - see * http://smartclient.com/license * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ import java.util.HashMap; import java.util.Map; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.fields.SelectItem; import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; import com.google.gwt.core.client.EntryPoint; public class FormDependentSelectsSample implements EntryPoint { public void onModuleLoad() { final DynamicForm form = new DynamicForm(); form.setWidth(500); form.setNumCols(4); final Map<String, String[]> departments = new HashMap<String, String[]>(); departments.put("Marketing", new String[]{"Advertising", "Community Relations"}); departments.put("Sales", new String[]{"Channel Sales", "Direct Sales"}); departments.put("Manufacturing", new String[]{"Design", "Development", "QA"}); departments.put("Services", new String[]{"Support", "Consulting"}); SelectItem divisionItem = new SelectItem(); divisionItem.setName("division"); divisionItem.setTitle("Division"); divisionItem.setValueMap("Marketing", "Sales", "Manufacturing", "Services"); divisionItem.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { String selectedItem = (String) event.getValue(); form.getField("department").setValueMap(departments.get(selectedItem)); } }); SelectItem departmentItem = new SelectItem(); departmentItem.setName("department"); departmentItem.setTitle("Department"); departmentItem.setAddUnknownValues(false); form.setItems(divisionItem, departmentItem); form.draw(); } }