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

标签 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 
  }; 
 } 
}   

创建我的按钮的程序。这是我想让我的按钮处于 Activity 状态的地方。

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


}

最佳答案

您可以使用文本字段或 Binder 上的监听器来完成此操作

textField.addValueChangeListener(e -> 
        myButton.setEnabled(!e.getValue().equals("")));

binder.addStatusChangeListener(e -> 
        myButton.setEnabled(!e.hasValidationErrors()));

关于java - 如何在使用 VAADIN 填充文本字段时启用按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53204337/

相关文章:

java - 如何在我的 Vaadin 服务中接收文件内容?

vaadin - 如何增加 Vaadin 通知/警告时间?

java - GAE : Exception while allocating 16 digit ids

java - 如何对嵌套标签进行替换并识别嵌套状态?

java - 集成 Vaadin 7 和 EJB 的最佳方式或如何制作服务层?

hibernate - Vaadin JpaContainer

javascript - vaadin-combo-box/vaadin-combo-box-overlay 更改背景颜色/polymer API

java - 无法使用包将一个java类的方法使用到第二个类中

java - 将值放入 LinkedHashMap 多维

java - 为什么我的代码运行在主线程上?