如何在使用VAADIN填充文本字段时启用按钮

woo*_*son 0 java vaadin

我和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 
  }; 
 } 
}   
Run Code Online (Sandbox Code Playgroud)

创建我的按钮的程序.这是我想让我的按钮处于活动状态的地方.

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());


}
Run Code Online (Sandbox Code Playgroud)

Taz*_*voo 5

您可以在文本字段或绑定器上使用侦听器来执行此操作

textField.addValueChangeListener(e -> 
        myButton.setEnabled(!e.getValue().equals("")));
Run Code Online (Sandbox Code Playgroud)

要么

binder.addStatusChangeListener(e -> 
        myButton.setEnabled(!e.hasValidationErrors()));
Run Code Online (Sandbox Code Playgroud)