我与Vaadin合作。我有一个文本字段和一个按钮。我的按钮最初被禁用。当我的文本字段中填充有效数据时,必须激活我的按钮。我无法激活我的按钮。你可以帮帮我吗 ?谢谢
public static DynTextField createFromElement(Element elt, DynForm form) {
if (elt.getNodeName().equals("param") && elt.getAttribute("type").equals("TEXT")) {
DynTextField dtf = new DynTextField();
dtf.setForm(form);
if (elt.hasAttribute("texte"))
dtf.setCaption(elt.getAttribute("texte"));
dtf.nom = elt.getAttribute("nom");
if (elt.hasAttribute("FORMAT"))
dtf.setFormat(elt.getAttribute("FORMAT"));
dtf.setDescription(elt.getAttribute("description"));
dtf.setStyleName("param" + (elt.hasAttribute("class") ? elt.getAttribute("class") : ""));
return dtf;
} else
return null;
}
private void setFormat(String attribute) {
binder = new Binder<>();
binder.forField(this).withValidator(new RegexpValidator("Saisie obligatoire !!", attribute)).asRequired("Format Erroné").bind(No.getter(), No.setter());
//new Binder<>().forField(this).withValidator(new RegexpValidator(attribute, "Format Erroné")).asRequired();
}
// convenience empty getter and setter implementation for better readability
public static class No {
public static <SOURCE, TARGET> ValueProvider<SOURCE, TARGET> getter() {
return source -> null;
}
public static <BEAN, FIELDVALUE> Setter<BEAN, FIELDVALUE> setter() {
return (bean, fieldValue) -> {
//no op
};
}
}
创建我的按钮的程序。这是我要激活按钮的地方。
public DynButton(DynForm form, String as400PGMName, String[] parameterList) {
super(VaadinIcons.CHECK);
this.as400PGMName = as400PGMName;
if (parameterList.length == 1 && parameterList[0].equals(""))
this.parameterList = new String[] {};
else
this.parameterList = parameterList;
this.form = form;
addClickListener(event -> {
fireClickEvent(event);
});
addClickListener(this);
impl = new DynComponentImpl();
//boutton initially disable
this.setEnabled(isActif());
}
答案 0 :(得分:5)
您可以在文本字段或活页夹中使用侦听器来实现
textField.addValueChangeListener(e ->
myButton.setEnabled(!e.getValue().equals("")));
或
binder.addStatusChangeListener(e ->
myButton.setEnabled(!e.hasValidationErrors()));