/* * SmartGWT (GWT for SmartClient) * Copyright 2008 and beyond, Isomorphic Software, Inc. * * SmartGWT 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. SmartGWT 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 com.smartgwt.client.data.Criteria; import com.smartgwt.client.data.DataSource; 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.ChangedEvent; import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; import com.smartgwt.sample.showcase.client.data.ItemSupplyXmlDS; import com.smartgwt.sample.showcase.client.data.SupplyCategoryXmlDS; public class FormDataboundDependentSelectsSample implements EntryPoint { public void onModuleLoad() { final DynamicForm form = new DynamicForm(); form.setWidth(500); form.setNumCols(4); DataSource itemSupplyDS = ItemSupplyXmlDS.getInstance(); DataSource supplyCategoryDS = SupplyCategoryXmlDS.getInstance(); final SelectItem categoryItem = new SelectItem(); categoryItem.setName("categoryName"); categoryItem.setPickListWidth(210); categoryItem.setTitle("Category"); categoryItem.setOptionDataSource(supplyCategoryDS); categoryItem.addChangedHandler(new ChangedHandler() { public void onChanged(ChangedEvent event) { form.clearValue("itemName"); } }); SelectItem itemName = new SelectItem() { protected Criteria getPickListFilterCriteria() { String category = (String) categoryItem.getValue(); Criteria criteria = new Criteria("category", category); return criteria; } }; itemName.setName("itemName"); itemName.setTitle("Item"); itemName.setPickListWidth(250); itemName.setOptionDataSource(itemSupplyDS); form.setItems(categoryItem, itemName); form.draw(); } }