与SelectItem(smartGWT)一起使用的重复DataSource字段

时间:2012-09-30 08:15:13

标签: java gwt datasource smartgwt

我正在尝试在SelectItem组件中列出一个表。我为此目的使用ListGrid组件。这是代码:

    final ListGrid brandGrid = new ListGrid();

    ListGridField nameField = new ListGridField("name");
    ListGridField descriptionField = new ListGridField("description");
    ListGridField detailField = new ListGridField("detail");

    final SelectItem filterList = new SelectItem();
    filterList.setDisplayField("name");
    filterList.setValueField("description");
    filterList.setPickListWidth(400);


    filterList.setOptionDataSource(myDataSource);
    filterList.setPickListFields(nameField, descriptionField);
    filterList.setPickListProperties(brandGrid);
    filterList.setDefaultValue(record.getAttributeAsString("name"));
    filterList.setShowTitle(false);
    filterList.setStartRow(false);

myDataSource实例的DataSource代码(我在使用DataSource myDataSource之前调用此方法初始化类属性SelectItem filterList):

private DataSource getBrandData(List<BrandDB> result){
        DataSource ds = new DataSource();

        DataSourceTextField id = new DataSourceTextField();
        id.setName("idBrand");
        id.setPrimaryKey(true);

        DataSourceTextField name = new DataSourceTextField();
        name.setName("name");

        DataSourceTextField description = new DataSourceTextField();
        description.setName("description");

        ds.setFields(id, nazov, popis);

        ds.setClientOnly(true);
        for(int i = 0; i < result.size(); i++){
            Record rc = new Record();
            rc.setAttribute("idBrand", result.get(i).getIdBrand()+"");
            rc.setAttribute("name", result.get(i).getName());
            rc.setAttribute("description", result.get(i).getDescription());
            ds.addData(rc);
        }
        return ds;
    }

问题是我的数据源中的值description在几个地方有相同的值(这些值的id和名称不同)。我得到以下错误:

TMR0:WARN:fetchMissingValues:isc_SelectItem_1:Deriving valueMap for 'description' from dataSource based on displayField 'name'. This dataSource contains more than one record with description set to Not defined with differing name values. Derived valueMap is therefore unpredictable.

如何设置SelectItem以接受这些重复值?非常感谢您的回答。 :)

1 个答案:

答案 0 :(得分:0)

问题解决了:

错误位于以下代码行中:

filterList.setValueField("description");

描述不是唯一的,因为它不能是SelectItem组件中的值字段。有必要按如下方式编辑这行代码:

filterList.setValueField("idBrand");

idBrand是唯一的,因为它被定义为DataSource中的主键,因此SelectItem唯一地标识了它的值字段并且可以生成过滤器。