Vaadin Web应用开发教程(31):UI布局-FormLayout布局

jerry VaadinWeb 2015年11月25日 收藏

FormLayout布局为使用表单(Form)时的缺省布局方式。它通常将Field组件的标题和输入域并排以两列的方式显示,并可以显示可选的必填标识。在用户输入错误时显示错误提示。
Form本身可以有标题,错误提示,表单尾注等,具体参见Vaadin Web应用开发教程(23):UI组件-Form组件
FormLayout布局的基本用法如下:

  1. // A FormLayout used outside the context of a Form
  2. FormLayout fl = new FormLayout();
  3.  
  4. // Make the FormLayout shrink to its contents
  5. fl.setSizeUndefined();
  6.  
  7. TextField tf = new TextField("A Field");
  8. fl.addComponent(tf);
  9.  
  10. // Mark the first field as required
  11. tf.setRequired(true);
  12. tf.setRequiredError("The Field may not be empty.");
  13.  
  14. TextField tf2 = new TextField("Another Field");
  15. fl.addComponent(tf2);
  16.  
  17. // Set the second field straing to error state with a message.
  18. tf2.setComponentError(
  19. new UserError("This is the error indicator of a Field."));

显示如下: