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.

PropertyId.java 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.annotations;
  17. import java.lang.annotation.ElementType;
  18. import java.lang.annotation.Retention;
  19. import java.lang.annotation.RetentionPolicy;
  20. import java.lang.annotation.Target;
  21. import com.vaadin.data.BeanBinder;
  22. import com.vaadin.data.Binder;
  23. import com.vaadin.data.HasValue;
  24. /**
  25. * Defines the custom property name to be bound to a {@link Field} using
  26. * {@link Binder} or {@link BeanBinder}.
  27. * <p>
  28. * The automatic data binding in Binder and BeanBinder relies on a naming
  29. * convention by default: properties of an item are bound to similarly named
  30. * field components in given a editor object. If you want to map a property with
  31. * a different name (ID) to a {@link HasValue}, you can use this annotation for
  32. * the member fields, with the name (ID) of the desired property as the
  33. * parameter.
  34. * <p>
  35. * In following usage example, the text field would be bound to property "foo"
  36. * in the Entity class. <code>
  37. * <pre>
  38. * class Editor extends FormLayout {
  39. &#64;PropertyId("foo")
  40. TextField myField = new TextField();
  41. }
  42. class Entity {
  43. String foo;
  44. }
  45. {
  46. Editor editor = new Editor();
  47. BeanBinder<Entity> binder = new BeanBinder(Entity.class);
  48. binder.bindInstanceFields(editor);
  49. }
  50. </pre>
  51. * </code>
  52. *
  53. * @since 7.0
  54. * @author Vaadin Ltd
  55. */
  56. @Target({ ElementType.FIELD })
  57. @Retention(RetentionPolicy.RUNTIME)
  58. public @interface PropertyId {
  59. String value();
  60. }