D
Dave
I am using glazed lists to create JTables from simple POJO objects.
With my understanding of glazed lists you basically need to create a
TableFormat and TextFilterator for each POJO in order to create the
table (with filtering). I am trying to use reflection to dynamically
determine the column count, column names and column values. Here is
how I access the POJO objects in order to get the column values:
/* */
public Object getColumnValue(Object baseObject, int column)
{
Object columnValue = null;
Class c = baseObject.getClass();
Field [] fields = c.getDeclaredFields();
try
{
columnValue = fields[column].get(baseObject);
}
catch (IllegalAccessException e)
{
TalonAuditTrails.getInstance(this.getClass().toString()).exceptionThrown(e);
}
catch (Exception e)
{
TalonAuditTrails.getInstance(this.getClass().toString()).exceptionThrown(e);
}
return columnValue;
}
Here's the rub:
The attributes must be declared as public in the POJO to use this
method; which I don't want to because I feel this is bad design.
Is there a better way to do this with reflection?
With my understanding of glazed lists you basically need to create a
TableFormat and TextFilterator for each POJO in order to create the
table (with filtering). I am trying to use reflection to dynamically
determine the column count, column names and column values. Here is
how I access the POJO objects in order to get the column values:
/* */
public Object getColumnValue(Object baseObject, int column)
{
Object columnValue = null;
Class c = baseObject.getClass();
Field [] fields = c.getDeclaredFields();
try
{
columnValue = fields[column].get(baseObject);
}
catch (IllegalAccessException e)
{
TalonAuditTrails.getInstance(this.getClass().toString()).exceptionThrown(e);
}
catch (Exception e)
{
TalonAuditTrails.getInstance(this.getClass().toString()).exceptionThrown(e);
}
return columnValue;
}
Here's the rub:
The attributes must be declared as public in the POJO to use this
method; which I don't want to because I feel this is bad design.
Is there a better way to do this with reflection?