Přidaná statická metoda, která vrací kolekci properties objektu.

multitenant
Josef Rokos 11 years ago
parent 426bbe1df3
commit 005c7fa7ef

@ -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<String> getEntityFields(Class<?> clazz) {
BeanInfo beanInfo;
try {
beanInfo = Introspector.getBeanInfo(clazz);
} catch (IntrospectionException e) {
return null;
}
PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
List<String> properties = new ArrayList<String>();
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<String> getEntityFields(Object entity) {
if (entity == null) {
return null;
}
return getEntityFields(entity.getClass());
}
}

@ -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<String> properties = new ArrayList<String>();
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<String> properties = ReflectionTools.getEntityFields(data.get(0));
ListChecks<String> columns = new ListChecks<String>(reportDefinition.getFieldsToPrint(), properties);
return columns;

Loading…
Cancel
Save