If you want, you don't even have to implement ITableColumnModel.
just do something like:
.html:
<table jwcid="@contrib:Table" source="ognl:theSource"
columns="ognl:columnList"/>
.java:
public List getColumnList() {
List ret = new ArrayList();
String columnId="callPointH";
String columnHeader="Call Point H";
//not that the root of your ognl expression is the current row obj.
String ognlExpression = "callPoinH";
boolean sortable=true;
ret.add(new
ExpressionTableColumn(columnId,columnHeeader,ognlExpression,sortable);
return ret;
}
Ryan Cuprak wrote:
> Hello,
> I am working creating a table for which the number of columns is dynamic
> (user can control which columns they want displayed). What is the proper
> approach for implementing the behavior?
>
> Thus far I created an implementation of ITableColumnModel which then
> returns the custom set of columns. I initially returned SimpleTableColumn
> instances but was getting a 'Unable to read OGNL expression '<parsed OGNL
> expression>' of [EMAIL PROTECTED]/image/bands.tableColumns]:
> tableColumnRenderer' exception (src below). After getting this exception I
> thought my approach might be wrong. Looking over the code I was a little
> puzzled on how my column would extract the values from the model etc. Looking
> through the contrib:table source I chanced upon 'ExpressionTableColumn'.
> There are no java docs so I am not quiet sure how it is supposed to be used.
> From the title I 'think' this would take ognl expressions and retrieve the
> values from my data model? However, I am not quiet sure how to contruct an
> instance - where/what do I use for an ExpressionEvaluator?
>
> Page spec:
> <component id="bands" type="Contrib:Table">
> <binding name="source" value="tableModel"/>
> <binding name="columns" value="ognl:tableColumnModel"/>
> <binding name="rowsClass" value="beans.evenOdd.next"/>
> <binding name="columnsClass" value="literal:title"/>
> </component>
>
> My TableColumnModel (only one field, was trying to get it working first..):
> public class BandSummaryColumnModel implements ITableColumnModel {
>
> private static final Logger logger =
> Logger.getLogger(BandSummaryColumnModel.class);
>
> private Map<String, ITableColumn> _columns;
>
> public BandSummaryColumnModel() {
> if(logger.isDebugEnabled()) logger.debug("Instantiating
> BandSummaryColumnModel");
> _columns = new HashMap<String,ITableColumn>();
> _columns.put("callPointH",new
> SimpleTableColumn("callPointH","callPointH",true));
> }
>
> public int getColumnCount() {
> if(logger.isDebugEnabled()) logger.debug("Column count: " +
> _columns.size());
> return _columns.size();
> }
>
> public ITableColumn getColumn(String string) {
> if(logger.isDebugEnabled()) logger.debug("Column requested: " +
> string);
> return _columns.get(string);
> }
>
> public Iterator getColumns() {
> if(logger.isDebugEnabled()) logger.debug("Column iterator requested");
> return _columns.entrySet().iterator();
> }
> }
>
> Thanks!
> Ryan
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]