我有一个带有FormItem的smartGwt DynamicForm
FormItem item = createTextItem();
form.setFields(item);
创建和设置字段后,我需要动态设置项目的编辑器类型。我必须根据某些条件动态地完成它。
我在呼叫item.setEditorType(new PasswordItem());
在我调用form.editRecord(record);
之后,应该出现新的编辑器类型。但它没有用。
尝试调用item.redraw()
但无效。
我的目标是根据编辑的记录动态设置编辑器类型。请帮助。
答案 0 :(得分:1)
尝试使用自定义数据绑定(see page 23了解更多详情)。您尝试过的内容是AFAIK,因为ListGridField
已经使用初始自定义编辑器创建,并且无法使用setEditorCustomizer
动态更改。
看看这个示例(基于this展示演示),它在您在DynamicForm中编辑密码字段时执行您想要做的事情,并在保存更改后(请注意评论,因为如果没有这些设置,它将无法按预期工作):
public void onModuleLoad() {
final DataSource dataSource = ItemSupplyLocalDS.getInstance();
final DynamicForm form = new DynamicForm();
form.setIsGroup(true);
form.setNumCols(4);
form.setDataSource(dataSource);
// very important for not having to set all fields all over again
// when the target field is customized
form.setUseAllDataSourceFields(true);
final ListGrid listGrid = new ListGrid();
listGrid.setWidth100();
listGrid.setHeight(200);
listGrid.setDataSource(dataSource);
listGrid.setAutoFetchData(true);
IButton editButton = new IButton("Edit");
editButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
form.editRecord(listGrid.getSelectedRecord());
// when the button is clicked, the password field is rendered with
// a plain text item editor, for easy verification of values entered
FormItem passwordField = new FormItem("passwordFieldName");
passwordField.setEditorProperties(new TextItem());
form.setFields(passwordField);
form.markForRedraw();
}
});
IButton saveButton = new IButton("Save");
saveButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
form.saveData();
// when the button is clicked, the password field is rendered with
// a password editor, for added privacy/security
FormItem passwordField = new FormItem("passwordFieldName");
passwordField.setEditorProperties(new PasswordItem());
form.setFields(passwordField);
form.markForRedraw();
}
});
VLayout layout = new VLayout(15);
layout.setWidth100();
layout.setHeight100();
layout.addMember(listGrid);
layout.addMember(editButton);
layout.addMember(form);
layout.addMember(saveButton);
layout.draw();
}