Smartgwt选择所有功能

时间:2013-11-07 09:02:26

标签: gwt smartgwt

需要帮助。选择所有功能。我创建了一个表单。

DynamicForm form = new DynamicForm();  
final SelectItem category = new SelectItem("category", "Employee Category");  
category.setMultiple(true);  
category.setValueMap("Direct","InDirect","ALL");  
form.setFields(category);  

如果我选择“全部”,也应该选择选项列表中的所有三个项目。如果我取消选择“全部”,则应该取消选择所有三个项目。需要帮助

1 个答案:

答案 0 :(得分:3)

您可以尝试以下方法:

boolean isAllSelected = false; // global variable
SelectItem selectItem = new SelectItem("category", "Employee Category");
selectItem.setMultiple(true);
selectItem.setMultipleAppearance(MultipleAppearance.PICKLIST);
selectItem.setValueMap("Direct","InDirect","ALL");
selectItem.addChangedHandler(new ChangedHandler() {

    @Override
    public void onChanged(ChangedEvent event) {
        if (event.getValue() != null) {
            if (event.getValue().toString().contains("ALL")) {
                if (!isAllSelected) {
                    selectItem.setValues("Direct","InDirect", "ALL");
                    isAllSelected = true;
                }
            } else {
                if (isAllSelected) {
                    selectItem.clearValue();
                }
                isAllSelected = false;
            }
        } else {
            isAllSelected = false;
        }
    }
});

DynamicForm form = new DynamicForm();
form.setSize("800px", "400px");
form.setFields(selectItem);
form.draw();