0

我正在尝试在 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 以接受这些重复值?非常感谢您的回答。:)

4

1 回答 1

0

问题解决了:

错误位于这行代码中:

filterList.setValueField("description");

描述不是唯一的,因此它不能是 SelectItem 组件内的值字段。只需编辑这行代码,如下所示:

filterList.setValueField("idBrand");

idBrand是唯一的,因为它被定义为 DataSource 中的主键,因此 SelectItem 已唯一标识其值字段并可以进行过滤。

于 2012-09-30T09:26:19.230 回答