You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "JONES, Nick" <Ni...@redenergy.com.au> on 2006/01/19 01:47:34 UTC

Expression Evaluator for dynamic table

Hi

Currently I have a few classes that dynamically construct a table model
depending on the dataset given to them.
The problem I have at the moment is that when I first submit my form the
results are displayed correctly with no exceptions logged. However if I
resubmit the form while my results are still displayed correctly the
exception below is logged.

148236 [http-8080-Processor22] ERROR
org.apache.tapestry.contrib.table.model.ognl.OgnlTableColumnEvaluator  -
Cannot use column expression 'get(2)' in row
java.lang.NullPointerException
	at
org.apache.tapestry.services.impl.ExpressionEvaluatorImpl.read(Expressio
nEvaluatorImpl.java:82)

I construct a list of table models and then output them in a @For loop
in the template. The code that constructs the table models is below:
SerializableExpressionEvaluatorImpl is just a child of
ExpressionEvaluatorImpl implementing Serializable 

//----------------------------------------------------------------------
---------------------------------------------------

public class TapestryTableReportSet extends ListReportSet {
  //Constants----------------------------
  private static final int PAGE_SIZE = 50;

  public static final TapestryTableReportSet EMPTY_TABLE_SET = new
TapestryTableReportSet();
  private static final Object[] NO_DATA = new Object[]{};
  private static final ITableColumn[] NO_COLUMNS = new ITableColumn[]{};

  static {
    EMPTY_TABLE_SET.tableModel = new SimpleTableModel(NO_DATA,
NO_COLUMNS);
  }

  //Properties----------------------------
  private ITableModel tableModel;

  //Constructors--------------------------
  public TapestryTableReportSet() {

  }

  public TapestryTableReportSet(ReportSet rs, List headings) {
    super(rs);

    /*this loop is to satisfy the constructor requirements of
ExpressionTableColumnModel*/
    String[] columns = new String[2 * headings.size()];
    for (int i = 0; i < headings.size(); i++) {
      columns[2 * i] = (String) headings.get(i);
      columns[2 * i + 1] = "get(" + i + ")";
    }

    SerializableExpressionEvaluatorImpl expressionEvaluator = new
SerializableExpressionEvaluatorImpl();
    expressionEvaluator.setExpressionCache(new ExpressionCacheImpl());

    tableModel = new SimpleTableModel(
      new SimpleListTableDataModel(recordList),
      new ExpressionTableColumnModel(columns, false,
expressionEvaluator)
    );

    /*
    TODO This is a temporary measure until we can see if a future tap4.0
beta
    release addresses the issue of paging causing a null pointer
exception
    in the expression cache.
    */
    tableModel.getPagingState().setPageSize(PAGE_SIZE);
  }

  //Methods Getters/Setters---------------

  public ITableModel getTableModel() {
    return tableModel;
  }

}

//----------------------------------------------------------------------
---------------------------------------------------

<span jwcid="@For" source="ognl:resultSet" value="ognl:singleReportSet">
          <span jwcid="@ReportTable" title="NMI's with Interval Meters"
                                     headerString="As of: "
                                     headerData="ognl:getReportDate()"
                                     footerString="Total: "
 
footerData="ognl:singleReportSet.getRecordCount()">
            <span jwcid="outputTableID@contrib:Table"
              tableModel="ognl:singleReportSet.getTableModel()"
              columnsClass="Pagebody_header"
              rowsClass="Pagebody_text"/>
          </span>
        </span>

//----------------------------------------------------------------------
---------------------------------------------------

When the form is submitted the following block is executed

protected void formSearch(String reportID, Set<String> outputTypes){
    Table tempTable = (Table) getComponent(OUTPUT_TABLE_ID);
    tempTable.reset();

    Map<String, Object> results =
getReportManager().runReport(reportID,prepareReportParameters(),outputTy
pes);
 
setResultSet((List<TapestryTableReportSet>)results.get(TapestryTableRepo
rtOutput.TAPESTRY_TABLE_OUTPUT_ID));
 
setHardReportByteResults((byte[])results.get(CsvReportOutput.CSV_REPORT_
OUTPUT_ID));
 
setGraphReportByteResults((List<byte[]>)results.get(TimeSeriesGraphRepor
tOutput.TS_GRAPH_REPORT_OUTPUT_ID));    
  } 

Does anyone have any suggestions on how to stop this exception being
thrown as its making a bit of a mess of our logs?

Thanks for your time
Nick Jones.



______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

Re: Expression Evaluator for dynamic table

Posted by Kent Tong <ke...@cpttm.org.mo>.
JONES, Nick <Nick.Jones <at> redenergy.com.au> writes:

> SerializableExpressionEvaluatorImpl is just a child of
> ExpressionEvaluatorImpl implementing Serializable 

I don't think you can make ExpressionEvaluatorImpl serialzable 
by simply subclassing it and implementing Serializable in
that subclass. Your subclass must serialize the private fields
in ExpressionEvaluatorImpl but some of them have no getters.

Instead, you should inject the tapestry.ognl.ExpressionEvaluator
service.

--
Author of a book for learning Tapestry (http://www.agileskills2.org/EWDT)


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org