Přidaná statická metoda, která vrací kolekci properties objektu.
This commit is contained in:
@@ -1,6 +1,12 @@
|
|||||||
package info.bukova.isspst.sort;
|
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.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ReflectionTools {
|
public class ReflectionTools {
|
||||||
|
|
||||||
@@ -46,4 +52,30 @@ public class ReflectionTools {
|
|||||||
|
|
||||||
throw new IllegalArgumentException("Not getter method found for '" + propertyName + "', bean: " + bean);
|
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;
|
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.Report;
|
||||||
import info.bukova.isspst.reporting.ReportDefinition;
|
import info.bukova.isspst.reporting.ReportDefinition;
|
||||||
import info.bukova.isspst.reporting.ReportType;
|
import info.bukova.isspst.reporting.ReportType;
|
||||||
|
import info.bukova.isspst.sort.ReflectionTools;
|
||||||
import info.bukova.isspst.ui.ListChecks;
|
import info.bukova.isspst.ui.ListChecks;
|
||||||
import info.bukova.isspst.ui.LocaleConverter;
|
import info.bukova.isspst.ui.LocaleConverter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.zkoss.bind.annotation.Init;
|
import org.zkoss.bind.annotation.Init;
|
||||||
import org.zkoss.zk.ui.select.annotation.WireVariable;
|
import org.zkoss.zk.ui.select.annotation.WireVariable;
|
||||||
|
|
||||||
@@ -38,19 +34,7 @@ public class ColSelectVM {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
BeanInfo beanInfo;
|
List<String> properties = ReflectionTools.getEntityFields(data.get(0));
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ListChecks<String> columns = new ListChecks<String>(reportDefinition.getFieldsToPrint(), properties);
|
ListChecks<String> columns = new ListChecks<String>(reportDefinition.getFieldsToPrint(), properties);
|
||||||
|
|
||||||
return columns;
|
return columns;
|
||||||
|
|||||||
Reference in New Issue
Block a user