Repository: syncope Updated Branches: refs/heads/2_0_X aa25af970 -> a95ff2380
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/a95ff238 Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/a95ff238 Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/a95ff238 Branch: refs/heads/2_0_X Commit: a95ff23803fe689007622e7b5e5023a0e5018a11 Parents: aa25af9 Author: Marco Di Sabatino Di Diodoro <marco.disabat...@tirasa.net> Authored: Mon Oct 30 15:41:19 2017 +0100 Committer: Marco Di Sabatino Di Diodoro <marco.disabat...@tirasa.net> Committed: Mon Oct 30 15:41:19 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/a95ff238/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 c09fb43..56c897d 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;