0

現在、 Vaadinを使用して最初のHello Worldを試していますが、最初の単純な検証済みフォームでスタックしています。フォームのforとしてを使用していますが、beanプロパティのバリデーターを追加する方法がわかりません。BeanItemItemDataSource

私の問題

FieldBeanのプロパティの実際を取得するにはどうすればよいですか?フィールドに電話する必要がありますaddValidator()が、でしか取得できませんForm

HelloWorldForm

package vaadinapp.hello;

import com.vaadin.data.util.BeanItem;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Form;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;

public class HelloWorldForm extends Form {
    HelloWorldBean data = new HelloWorldBean();

    public HelloWorldForm() {
        setCaption("Hello World");
        setDescription("This is a simple form that lets you enter your name and displays a greeting.");

        setItemDataSource(new BeanItem(data));

        setFooter(new VerticalLayout());
        getFooter().addComponent(
                new Label("This is the footer area of the Form. You can use any layout here. This is nice for buttons."));
        // Have a button bar in the footer.
        HorizontalLayout okbar = new HorizontalLayout();
        okbar.setHeight("25px");
        getFooter().addComponent(okbar);
        // Add an Ok (commit), Reset (discard), and Cancel buttons
        // for the form.
        Button okbutton = new Button("OK", this, "commit");
        okbar.addComponent(okbutton);
        okbar.setComponentAlignment(okbutton, Alignment.TOP_RIGHT);
        okbar.addComponent(new Button("Reset", this, "discard"));
        okbar.addComponent(new Button("Cancel"));
    }
}

HelloWorldBean

package vaadinapp.hello;

public class HelloWorldBean {
    String greeting;

    public String getGreeting() {
        return greeting;
    }

    public void setGreeting(String greeting) {
        this.greeting = greeting;
    }
}
4

2 に答える 2

3

プロパティにバリデーターを直接追加することはできません。バリデーターはフィールド自体に追加する必要があります(たとえば、フォーム内のフィールドまたはスタンドアロンのTexField)。

フォームの検証については、Book of Vaadinの5.17.3章を参照してください。http://vaadin.com/book/-/page/components.form.html getField(id)メソッドも含まれていることに注意してください。 FieldFactoryの代わりに使用できるフォーム)

于 2010-11-02T21:43:55.287 に答える
0

あなたが探しているのは Bean 検証アドオンだと思います。それを使用すると、プロパティに @NotNull を追加するなどのことができ、生成されたフィールドは自動的に必須としてマークされます。

https://vaadin.com/directory#addon/vaadin-bean-validation

于 2012-05-07T23:21:18.713 に答える