Vaadin在Panel类中设置TextFIeld值

时间:2015-05-06 05:23:50

标签: vaadin

我在扩展Panel的类中设置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; }
}

但是当我访问它的setter方法为特定Component设置值时,它什么也没做,仍然是值为空..

1 个答案:

答案 0 :(得分:0)

我终于得到了这个问题的答案.. 但我的技术是我让我的主类有一个静态方法,它调用面板getter和setter方法..这就是我如何解决我的问题..但这是一个合适的做法吗?