为密码

时间:2016-07-28 15:02:54

标签: smartgwt listgrid

我的配置屏幕有com.smartgwt.client.widgets.grid.ListGrid 我有3个ListGridFields 名称 isHidden
如果 isHidden 为true,我想使用 PasswordItem ;如果隐藏,则 TextItem 为false。

如何自定义网格?

我尝试使用setEditorCustomizer,但它仅在我编辑单元格时有效。在查看模式下,我可以看到文本。

2 个答案:

答案 0 :(得分:0)

我认为没有办法做你想做的事情(在可视化ListGrid的字段时显示PasswordItem编辑器)。如您所知,setEditorCustomizer仅在编辑模式下有效。

但您可以屏蔽字段值。以下是如何做到这一点:

// very important for not having to set all fields all over again
// when the target field is customized
listGrid.setUseAllDataSourceFields(true);

// customize the isHidden field to make it respond to changes and
// hide/show the password field accordingly
ListGridField isHidden = new ListGridField("isHiddenFieldName");
isHidden.addChangedHandler(new ChangedHandler() {
    @Override
    public void onChanged(ChangedEvent event) {
        // the name of this field has to match the name of the field you
        // want to hide (as defined in your data source descriptor, 
        // ListGridField definition, etc).
        ListGridField passwordField = new ListGridField("passwordFieldName");
        if ((Boolean) event.getValue() == true) {
            passwordField.setCellFormatter(new CellFormatter() {
                @Override
                public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
                    return ((String) value).replaceAll(".", "*");
                }
            });
        }
        // you need to re-add here the isHidden field for the ChangeHandler to
        // be present when recreating the ListGrid
        listGrid.setFields(isHidden, passwordField);  
        listGrid.markForRedraw();
    }
});
// add the customized field to the listGrid, so that we can have the
// desired ChangeHandler for the isHidden field
listGrid.setFields(isHidden);

答案 1 :(得分:0)

请记住,如果你隐藏价值(或使用PassowrdItem),那么“专家”就是这样做的。用户可以看到该值,只是因为服务器 将值发送给客户端。

如果您确实有安全约束,则可以使用DataSourceField.viewRequires,它接受速度表达式。