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
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;
+ }
+}
--- /dev/null
+package com.vaadin.data.util;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.vaadin.data.fieldgroup.FieldGroup;
+import com.vaadin.data.fieldgroup.PropertyId;
+import com.vaadin.ui.TextField;
+
+public class ReflectToolsGetSuperField {
+
+ @Test
+ public void getFieldFromSuperClass() {
+ class MyClass {
+ @PropertyId("testProperty")
+ TextField test = new TextField("This is a test");
+ }
+ class MySubClass extends MyClass {
+ // no fields here
+ }
+
+ PropertysetItem item = new PropertysetItem();
+ item.addItemProperty("testProperty", new ObjectProperty<String>("Value of testProperty"));
+
+ MySubClass form = new MySubClass();
+
+ FieldGroup binder = new FieldGroup(item);
+ binder.bindMemberFields(form);
+
+ assertTrue("Value of testProperty".equals(form.test.getValue()));
+ }
+
+}