You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by md...@apache.org on 2017/10/30 14:44:57 UTC

syncope git commit: Improved the reading of the fields of a bean for the building of the form

Repository: syncope
Updated Branches:
  refs/heads/master bc3c6e616 -> 5697a5f90


Improved the reading of the fields of a bean for the building of the form


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/5697a5f9
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/5697a5f9
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/5697a5f9

Branch: refs/heads/master
Commit: 5697a5f90a9e26547012f37040efff1eba90ba34
Parents: bc3c6e6
Author: Marco Di Sabatino Di Diodoro <ma...@tirasa.net>
Authored: Mon Oct 30 15:41:19 2017 +0100
Committer: Marco Di Sabatino Di Diodoro <ma...@tirasa.net>
Committed: Mon Oct 30 15:44:34 2017 +0100

----------------------------------------------------------------------
 .../client/console/panels/BeanPanel.java        | 27 ++++++++++++--------
 1 file changed, 16 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/5697a5f9/client/console/src/main/java/org/apache/syncope/client/console/panels/BeanPanel.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/panels/BeanPanel.java b/client/console/src/main/java/org/apache/syncope/client/console/panels/BeanPanel.java
index 96ee931..cc8d75d 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/panels/BeanPanel.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/panels/BeanPanel.java
@@ -65,6 +65,9 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanWrapper;
 import org.springframework.beans.PropertyAccessorFactory;
 import org.springframework.util.ClassUtils;
+import org.springframework.util.ReflectionUtils;
+import org.springframework.util.ReflectionUtils.FieldCallback;
+import org.springframework.util.ReflectionUtils.FieldFilter;
 
 public class BeanPanel<T extends Serializable> extends Panel {
 
@@ -100,16 +103,23 @@ public class BeanPanel<T extends Serializable> extends Panel {
 
             @Override
             protected List<String> load() {
-                List<String> result = new ArrayList<>();
+                final List<String> result = new ArrayList<>();
 
                 if (BeanPanel.this.getDefaultModelObject() != null) {
-                    for (Field field : BeanPanel.this.getDefaultModelObject().getClass().getDeclaredFields()) {
-                        if (!BeanPanel.this.excluded.contains(field.getName())) {
+                    ReflectionUtils.doWithFields(BeanPanel.this.getDefaultModelObject().getClass(),
+                            new FieldCallback() {
+
+                        public void doWith(final Field field) throws IllegalArgumentException, IllegalAccessException {
                             result.add(field.getName());
                         }
-                    }
-                }
 
+                    }, new FieldFilter() {
+
+                        public boolean matches(final Field field) {
+                            return !BeanPanel.this.excluded.contains(field.getName());
+                        }
+                    });
+                }
                 return result;
             }
         };
@@ -125,12 +135,7 @@ public class BeanPanel<T extends Serializable> extends Panel {
 
                 item.add(new Label("fieldName", new ResourceModel(fieldName, fieldName)));
 
-                Field field = null;
-                try {
-                    field = bean.getObject().getClass().getDeclaredField(fieldName);
-                } catch (NoSuchFieldException | SecurityException e) {
-                    LOG.error("Could not find field {} in class {}", fieldName, bean.getObject().getClass(), e);
-                }
+                Field field = ReflectionUtils.findField(bean.getObject().getClass(), fieldName);
 
                 if (field == null) {
                     return;