确定按钮无法在vaadin中工作

时间:2018-05-10 12:42:33

标签: java spring-mvc onclick vaadin

我有一个子窗口,其中包含一个文本字段和两个按钮确定和取消。当我点击确定按钮时,没有任何事情发生。我不明白我犯了什么错误。有人可以帮我弄这个吗。另外,我想知道如何将多个电子邮件地址放在一个由分号分隔的文本字段中。

这是我的代码

更新:大家好,我解决了这个问题。谢谢

package com.xitee.ccpt.ui.window;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;

import com.vaadin.data.Binder;
import com.vaadin.data.HasValue.ValueChangeEvent;
import com.vaadin.data.validator.EmailValidator;
import com.vaadin.ui.FormLayout;
import com.vaadin.ui.TextField;
import com.xitee.ccpt.entity.Person;
import com.xitee.ccpt.entity.Phone;

public class PersonWindow extends DialogWindow<Person>{
     private static final String WINDOW_WIDTH = "400px";
     private static final String WINDOW_HEIGHT = "270px";
     private static final String ENTER_VALID_EMAIL_ADDRESS = "Enter valid email address";

     private final FormLayout mainLayout;

     private final TextField efield;

     private Person email;
     private static final Logger LOGGER = LoggerFactory.getLogger(PersonWindow.class);

    public PersonWindow(String title, DialogWindowListener<Person> listener ) {
     this (title, listener,"");
        // TODO Auto-generated constructor stub
    }

    public PersonWindow(String title, DialogWindowListener<Person> listener, String type)
    {
        super(title, listener, WINDOW_WIDTH, WINDOW_HEIGHT);
        LOGGER.info("Creating dialog window: Email window");



        mainLayout = new FormLayout();


        efield = new TextField("Email:");


        mainLayout.addComponent(efield);

        init(mainLayout);

        doFieldValidations();

    }

    Binder<Person> binder = new Binder<>(Person.class);

    @Override
    protected void doFieldValidations() {
        // TODO Auto-generated method stub
        binder.forField(efield).withValidator(new EmailValidator(ENTER_VALID_EMAIL_ADDRESS));



    }

     public void setEmail(Person email)
        {
            LOGGER.info("Loading Email  " + email.getPersonId() + " into email dialog window");

            efield.setValue(email.getEmail());
            this.email = email;
        }

    @Override
    protected boolean confirmed() {

        if (!isEmpty())
        {
            if (isValid())
            {
                if (email == null)
                {
                    email = new Person();
                }

                email.setEmail(efield.getValue());


                listener.dialogConfirmed(email);
            }
            else
            {
                return false;
            }
        }

        return true;
    }

    @Override
    protected boolean isEmpty() {

        boolean ret = true;
        if (!StringUtils.isEmpty(efield.getValue()))
        {
            ret = false;
        }
        return ret;
    }


    @Override
    protected boolean isValid() {
        return false;

}

}

OK按钮的代码

Button okButton = new Button("OK");
        okButton.addClickListener(new ClickListener()
        {
            private static final long serialVersionUID = 2387863967859745591L;
            @Override
            public void buttonClick(ClickEvent event)
            {
                if (confirmed())
                {
                    close();
                }
            }
        });
        buttonPanel.addComponents(cancelButton, okButton);
    }

0 个答案:

没有答案