Java Vaadin如何在保存验证失败时重置Vaadin中的TextArea值
如果保存操作验证失败,如何重置Vaadin中Java Vaadin如何在保存验证失败时重置Vaadin中的TextArea值,java,textarea,vaadin,textfield,Java,Textarea,Vaadin,Textfield,如果保存操作验证失败,如何重置Vaadin中TextArea的值。我的代码如下: 它为文本区域提供从DB检索到的文本“A” 然后我想将文本区域更改为文本“B” 当“B”hass验证失败且B未保存到DB时,我希望在文本区域中看到文本“A”,但显示文本“B” 我的代码出了什么问题?已解决,只需updateName()方法中的纯Java即可: VerticalLayout content = new VerticalLayout(); TextArea text = new TextArea();
TextArea
的值。我的代码如下:
我的代码出了什么问题?已解决,只需updateName()方法中的纯Java即可:
VerticalLayout content = new VerticalLayout();
TextArea text = new TextArea();
text.setValue(controller.getFile().getName());
text.setRequired(true);
Button save = new Button("Save", event -> {
try {
newName.validate();
if (controller.getFile().updateName((text.getValue()))){
close();
} else{
System.out.println("WRONG TEXT!");
}
} catch (Validator.InvalidValueException ex) {
text.setValidationVisible(true);
}
});
save.setSizeFull();
content.addComponent(text);
content.addComponent(save);
setContent(content);
public boolean updateName(String newName) {
if (controller.getFile()!=null) {
controller.saveFileName(controller.getFile());
file.setName(newName); // mistake was in this line.
}
return false;
}