diff options
author | Jonni Nakari <jonni@vaadin.com> | 2012-12-13 14:58:18 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2012-12-17 11:47:31 +0000 |
commit | 5c8d4c1f5dfa4f6fb2e73728e2c0512d3e5c7446 (patch) | |
tree | d25b563dab029a28e89279ea24a1be2277f3950f /server/src/com/vaadin/data/fieldgroup | |
parent | c7070fc5754213b5d55c3db2d0fa52917f3bb544 (diff) | |
download | vaadin-framework-5c8d4c1f5dfa4f6fb2e73728e2c0512d3e5c7446.tar.gz vaadin-framework-5c8d4c1f5dfa4f6fb2e73728e2c0512d3e5c7446.zip |
Search fields from superclasses #10504
Modified buildAndBindMemberFields method to use a new
getFieldsInDeclareOrder method that searches fields also from
superclasses. Added a unit test to verify the new logic. Fixes the issue
in ticket #10504
Change-Id: Ic855e274c5b4d1c83760d6c2c53c67413a1da42c
Diffstat (limited to 'server/src/com/vaadin/data/fieldgroup')
-rw-r--r-- | server/src/com/vaadin/data/fieldgroup/FieldGroup.java | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/server/src/com/vaadin/data/fieldgroup/FieldGroup.java b/server/src/com/vaadin/data/fieldgroup/FieldGroup.java index 51cd3126cb..8803054857 100644 --- a/server/src/com/vaadin/data/fieldgroup/FieldGroup.java +++ b/server/src/com/vaadin/data/fieldgroup/FieldGroup.java @@ -794,8 +794,7 @@ public class FieldGroup implements Serializable { boolean buildFields) throws BindException { Class<?> objectClass = objectWithMemberFields.getClass(); - for (java.lang.reflect.Field memberField : objectClass - .getDeclaredFields()) { + for (java.lang.reflect.Field memberField : getFieldsInDeclareOrder(objectClass)) { if (!Field.class.isAssignableFrom(memberField.getType())) { // Process next field @@ -1001,4 +1000,27 @@ public class FieldGroup implements Serializable { field.setCaption(caption); return field; } -}
\ No newline at end of file + + /** + * Returns an array containing Field objects reflecting all the fields of + * the class or interface represented by this Class object. The elements in + * the array returned are sorted in declare order from sub class to super + * class. + * + * @param searchClass + * @return + */ + protected static List<java.lang.reflect.Field> getFieldsInDeclareOrder( + Class searchClass) { + ArrayList<java.lang.reflect.Field> memberFieldInOrder = new ArrayList<java.lang.reflect.Field>(); + + while (searchClass != null) { + for (java.lang.reflect.Field memberField : searchClass + .getDeclaredFields()) { + memberFieldInOrder.add(memberField); + } + searchClass = searchClass.getSuperclass(); + } + return memberFieldInOrder; + } +} |