diff --git a/src/main/java/info/bukova/isspst/sort/ReflectionTools.java b/src/main/java/info/bukova/isspst/sort/ReflectionTools.java index 5a2902e6..ed363745 100644 --- a/src/main/java/info/bukova/isspst/sort/ReflectionTools.java +++ b/src/main/java/info/bukova/isspst/sort/ReflectionTools.java @@ -1,6 +1,12 @@ package info.bukova.isspst.sort; +import java.beans.BeanInfo; +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; public class ReflectionTools { @@ -46,4 +52,30 @@ public class ReflectionTools { throw new IllegalArgumentException("Not getter method found for '" + propertyName + "', bean: " + bean); } + + public static List getEntityFields(Class clazz) { + BeanInfo beanInfo; + try { + beanInfo = Introspector.getBeanInfo(clazz); + } catch (IntrospectionException e) { + return null; + } + PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors(); + List properties = new ArrayList(); + for (PropertyDescriptor pd : pds) { + if (!(pd.getName().equals("password") || pd.getName().equals("class") || pd.getName().equals("id") || pd.getName().equals("valid"))) { + properties.add(pd.getName()); + } + } + + return properties; + } + + public static List getEntityFields(Object entity) { + if (entity == null) { + return null; + } + + return getEntityFields(entity.getClass()); + } } diff --git a/src/main/java/info/bukova/isspst/ui/reporting/ColSelectVM.java b/src/main/java/info/bukova/isspst/ui/reporting/ColSelectVM.java index 6036514c..f22bd68b 100644 --- a/src/main/java/info/bukova/isspst/ui/reporting/ColSelectVM.java +++ b/src/main/java/info/bukova/isspst/ui/reporting/ColSelectVM.java @@ -1,18 +1,14 @@ package info.bukova.isspst.ui.reporting; -import java.beans.BeanInfo; -import java.beans.IntrospectionException; -import java.beans.Introspector; -import java.beans.PropertyDescriptor; -import java.util.ArrayList; -import java.util.List; - import info.bukova.isspst.reporting.Report; import info.bukova.isspst.reporting.ReportDefinition; import info.bukova.isspst.reporting.ReportType; +import info.bukova.isspst.sort.ReflectionTools; import info.bukova.isspst.ui.ListChecks; import info.bukova.isspst.ui.LocaleConverter; +import java.util.List; + import org.zkoss.bind.annotation.Init; import org.zkoss.zk.ui.select.annotation.WireVariable; @@ -38,19 +34,7 @@ public class ColSelectVM { return null; } - BeanInfo beanInfo; - try { - beanInfo = Introspector.getBeanInfo(data.get(0).getClass()); - } catch (IntrospectionException e) { - return null; - } - PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors(); - List properties = new ArrayList(); - for (PropertyDescriptor pd : pds) { - if (!(pd.getName().equals("password") || pd.getName().equals("class") || pd.getName().equals("id") || pd.getName().equals("valid"))) { - properties.add(pd.getName()); - } - } + List properties = ReflectionTools.getEntityFields(data.get(0)); ListChecks columns = new ListChecks(reportDefinition.getFieldsToPrint(), properties); return columns;