import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.SelectItem;

public class FormDataBindingSample implements EntryPoint
{
    String[] numberValues = new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };

    @Override
    public void onModuleLoad()
    {
        // Create the DataSource.
        DataSource dataSource = new DataSource();

        DataSourceTextField singleNumTextField = new DataSourceTextField("singleNumText",
                "Single Number Text", 50, true);

        DataSourceIntegerField singleNumIntegerField = new DataSourceIntegerField(
                "singleNumInteger", "Single Number Integer", 50, true);

        DataSourceTextField multipleNumTextField = new DataSourceTextField("multipleNumText",
                "Multiple Numbers Text", 50, true);
        multipleNumTextField.setMultiple(true);

        DataSourceIntegerField multipleNumIntegerField = new DataSourceIntegerField(
                "multipleNumInteger", "Multiple Numbers Integer", 50, true);
        multipleNumIntegerField.setMultiple(true);

        dataSource.setFields(singleNumTextField, singleNumIntegerField, multipleNumTextField,
                multipleNumIntegerField);

        // Create the form bound to the DataSource.
        final DynamicForm form = new DynamicForm();
        form.setDataSource(dataSource);
        form.setUseAllDataSourceFields(true);
        form.setWrapItemTitles(false);

        // THIS SHOWS JUST FINE
        SelectItem singleNumSelectItemText = new SelectItem("singleNumText");
        singleNumSelectItemText.setEmptyDisplayValue("choose one number");
        singleNumSelectItemText.setValueMap(numberValues);

        // THIS DOESN'T SHOW
        SelectItem singleNumSelectItemInteger = new SelectItem("singleNumInteger");
        singleNumSelectItemInteger.setEmptyDisplayValue("choose one number");
        singleNumSelectItemInteger.setValueMap(numberValues);

        // THIS SHOWS JUST FINE
        SelectItem multipleNumSelectItemText = new SelectItem("multipleNumText");
        multipleNumSelectItemText.setEmptyDisplayValue("choose multiple numbers");
        multipleNumSelectItemText.setValueMap(numberValues);

        // THIS DOESN'T SHOW
        SelectItem multipleNumSelectItemInteger = new SelectItem("multipleNumInteger");
        multipleNumSelectItemInteger.setEmptyDisplayValue("choose multiple numbers");
        multipleNumSelectItemInteger.setValueMap(numberValues);

        form.setFields(singleNumSelectItemText, singleNumSelectItemInteger,
                multipleNumSelectItemText, multipleNumSelectItemInteger);

        form.draw();

        // Just for good measure, make sure everything is cleared and that we
        // don't have data loaded.
        form.clearValues();
        form.editNewRecord();
    }

}