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.

FieldNamedDescriptionTest.java 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package com.vaadin.v7.tests.server.component.fieldgroup;
  2. import static org.junit.Assert.assertTrue;
  3. import org.junit.Test;
  4. import com.vaadin.annotations.PropertyId;
  5. import com.vaadin.ui.FormLayout;
  6. import com.vaadin.v7.data.fieldgroup.FieldGroup;
  7. import com.vaadin.v7.data.util.ObjectProperty;
  8. import com.vaadin.v7.data.util.PropertysetItem;
  9. import com.vaadin.v7.ui.TextField;
  10. public class FieldNamedDescriptionTest {
  11. @Test
  12. public void bindReadOnlyPropertyToFieldGroup() {
  13. // Create an item
  14. PropertysetItem item = new PropertysetItem();
  15. item.addItemProperty("name", new ObjectProperty<String>("Zaphod"));
  16. item.addItemProperty("description",
  17. new ObjectProperty<String>("This is a description"));
  18. // Define a form as a class that extends some layout
  19. class MyForm extends FormLayout {
  20. // Member that will bind to the "name" property
  21. TextField name = new TextField("Name");
  22. // This member will not bind to the desctiptionProperty as the name
  23. // description conflicts with something in the binding process
  24. @PropertyId("description")
  25. TextField description = new TextField("Description");
  26. public MyForm() {
  27. // Add the fields
  28. addComponent(name);
  29. addComponent(description);
  30. }
  31. }
  32. // Create one
  33. MyForm form = new MyForm();
  34. // Now create a binder that can also creates the fields
  35. // using the default field factory
  36. FieldGroup binder = new FieldGroup(item);
  37. binder.bindMemberFields(form);
  38. assertTrue(form.description.getValue().equals("This is a description"));
  39. }
  40. }