在 smartGwt 中动态更改表单项编辑器类型
Change form item editor type dynamically in smartGwt
我有一个带有 FormItem 的 smartGwt DynamicForm
FormItem item = createTextItem();
form.setFields(item);
创建和设置字段后,我需要为项目动态设置编辑器类型。我必须根据某些条件动态地进行。
我打电话给item.setEditorType(new PasswordItem());
在我调用 form.editRecord(record);
之后,新的编辑器类型就会出现。但它不起作用。
已尝试调用 item.redraw()
但无法正常工作。
我的目标是根据 edited.Please 帮助的记录动态设置编辑器类型。
尝试使用自定义数据绑定(see page 23 for more details). What you tried won't work, 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();
}
我有一个带有 FormItem 的 smartGwt DynamicForm
FormItem item = createTextItem();
form.setFields(item);
创建和设置字段后,我需要为项目动态设置编辑器类型。我必须根据某些条件动态地进行。
我打电话给item.setEditorType(new PasswordItem());
在我调用 form.editRecord(record);
之后,新的编辑器类型就会出现。但它不起作用。
已尝试调用 item.redraw()
但无法正常工作。
我的目标是根据 edited.Please 帮助的记录动态设置编辑器类型。
尝试使用自定义数据绑定(see page 23 for more details). What you tried won't work, 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();
}