You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FormUsingExistingLayout.java 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package com.vaadin.tests.minitutorials.v7a1;
  2. import com.vaadin.annotations.PropertyId;
  3. import com.vaadin.server.VaadinRequest;
  4. import com.vaadin.tests.components.AbstractReindeerTestUI;
  5. import com.vaadin.ui.GridLayout;
  6. import com.vaadin.v7.data.fieldgroup.FieldGroup;
  7. import com.vaadin.v7.data.util.BeanItem;
  8. import com.vaadin.v7.ui.TextArea;
  9. import com.vaadin.v7.ui.TextField;
  10. public class FormUsingExistingLayout extends AbstractReindeerTestUI {
  11. public static class Notice {
  12. String firstName;
  13. String lastName;
  14. String message;
  15. public Notice(String firstName, String lastName, String message) {
  16. this.firstName = firstName;
  17. this.lastName = lastName;
  18. this.message = message;
  19. }
  20. public String getFirstName() {
  21. return firstName;
  22. }
  23. public void setFirstName(String firstName) {
  24. this.firstName = firstName;
  25. }
  26. public String getLastName() {
  27. return lastName;
  28. }
  29. public void setLastName(String lastName) {
  30. this.lastName = lastName;
  31. }
  32. public String getMessage() {
  33. return message;
  34. }
  35. public void setMessage(String message) {
  36. this.message = message;
  37. }
  38. }
  39. public static class MyFormLayout extends GridLayout {
  40. private TextField firstName = new TextField("First name");
  41. private TextField lastName = new TextField("Last name");
  42. // The name of the property is by default the name of the member field,
  43. // but it can be redefined with the @PropertyId annotation
  44. @PropertyId("message")
  45. private TextArea messageField = new TextArea("Your message");
  46. public MyFormLayout() {
  47. // Set up the GridLayout
  48. super(2, 3);
  49. setSpacing(true);
  50. // Add the (currently unbound) fields
  51. addComponent(firstName);
  52. addComponent(lastName);
  53. addComponent(messageField, 0, 1, 1, 1);
  54. messageField.setWidth("100%");
  55. }
  56. }
  57. @Override
  58. protected void setup(VaadinRequest request) {
  59. // Create the layout
  60. MyFormLayout myFormLayout = new MyFormLayout();
  61. // Create a field group and use it to bind the fields in the layout
  62. FieldGroup fieldGroup = new FieldGroup(
  63. new BeanItem<>(new Notice("John", "Doe", "")));
  64. fieldGroup.bindMemberFields(myFormLayout);
  65. addComponent(myFormLayout);
  66. }
  67. @Override
  68. protected String getTestDescription() {
  69. return "Mini tutorial for https://vaadin.com/wiki/-/wiki/Main/Creating%20a%20form%20using%20an%20existing%20layout";
  70. }
  71. @Override
  72. protected Integer getTicketNumber() {
  73. return null;
  74. }
  75. }