Vaadin在面板类中设置TextField值



我在扩展面板的类中设置TextField值时有一个问题。这是我的代码。

package com.example.examplejpa;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.FormLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Panel;
import com.vaadin.ui.TextField;
public class PersonnalInfoPanel extends Panel
{

    /**
     * 
     */
    private static final long serialVersionUID = 680441095924886309L;
    private TextField claimantName;
    private TextField insuredName;
    private TextField dateofbirth;
    private TextField age;
    private TextField dateFrom;
    private TextField dateTo;
    private TextField noDays;
    private ComboBox cause;
    private SearchButton searchBtn = new SearchButton();

    public PersonnalInfoPanel ()
    {
        setCaption("PERSONAL DATA INFO");
        setWidth("500px");
        FormLayout form = new FormLayout();
        form.setSpacing(true);
        form.setMargin(true);
        form.addComponent(searchBtn);
        claimantName = new TextField();
        claimantName.setCaption("Claimant Name");
        claimantName.setWidth("70%");
        form.addComponent(claimantName);
        insuredName = new TextField();
        insuredName.setCaption("Insured Name");
        insuredName.setWidth("70%");
        form.addComponent(insuredName);
        HorizontalLayout dateAge = new HorizontalLayout();
        dateAge.setSpacing(true);
        dateAge.setWidth("70%");
        dateofbirth = new TextField();
        dateofbirth.setCaption("Date of Birth");
        dateofbirth.setWidth("100%");
        dateAge.addComponent(dateofbirth);
        age = new TextField();
        age.setCaption("Age");
        age.setWidth("100%");
        dateAge.addComponent(age);
        form.addComponent(dateAge);
        HorizontalLayout dateRange = new HorizontalLayout();
        dateRange.setSpacing(true);
        dateRange.setWidth("70%");
        dateFrom = new TextField();
        dateFrom.setCaption("Date From");
        dateFrom.setWidth("100%");
        dateRange.addComponent(dateFrom);
        dateTo = new TextField();
        dateTo.setCaption("Date To");
        dateTo.setWidth("100%");
        dateRange.addComponent(dateTo);
        form.addComponent(dateRange);
        noDays = new TextField();
        noDays.setCaption("No. of Days");
        noDays.setWidth("70%");
        form.addComponent(noDays);
        cause = new ComboBox();
        cause.setCaption("Cause");
        cause.setWidth("70%");
        form.addComponent(cause);
        setContent(form);
    }
    public void setInsuredName (String newInsureName) { this.insuredName.setValue(newInsureName); }
    public void setClaimantName (String newClaimantName) { this.claimantName.setValue("awd"); System.out.println(newClaimantName); }
    public void setDateofbirth (String newDateofbirth) { this.dateofbirth.setValue(newDateofbirth); }
    public void setAge (String newAge) { this.age.setValue(newAge); }
    public void setDateFrom (String newDateFrom) { this.dateFrom.setValue(newDateFrom); }
    public void setDateTo (String newDateTo) { this.dateTo.setValue(newDateTo); }
    public void setNoDay (String newNoDay) { this.noDays.setValue(newNoDay); }
    public TextField getClaimantName () { return this.claimantName; }
}

但是,当我访问其设置器方法以设置特定组件的值时,它无能为力,仍然是空的。

我终于回答了这个问题。但是我的技术是让我的主要班级具有一种静态方法,该方法调用面板getter和setter方法。这就是我解决问题的方法。但是这样做是适当的吗?

最新更新