【问题标题】:Customize SmartGwt ListGrid dynamically for passwords为密码动态自定义 SmartGwt ListGrid
【发布时间】:2016-07-29 20:57:17
【问题描述】:

我的配置屏幕有一个com.smartgwt.client.widgets.grid.ListGrid
我有 3 个 ListGridFields namevalueisHidden
如果 isHidden 为真,我想使用 PasswordItem,如果 isidden 为假,我想使用 TextItem

如何自定义网格?

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

【问题讨论】:

    标签: smartgwt listgrid


    【解决方案1】:

    我不认为有办法做你想做的事(在可视化 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);
    

    【讨论】:

      【解决方案2】:

      请记住,如果您隐藏该值(或使用 PassowrdItem),“专家”用户可以看到该值,这仅仅是因为服务器将值发送到客户端。 p>

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多