You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "juceri@ya.com" <ju...@ya.com> on 2003/05/19 23:56:16 UTC

(SOLUTION) NullPointerException using SQLTableModel

Hi!

Some days ago I send a email asking about a problem using SQLTableModel.

The problem was that when it gets the last table record I get a 
NullPointerException.

Debugging I've seen that the problem begins in the 
org.apache.tapestry.contrib.table.model.sql.ResultSetIterator class.
Inside the hasNext method, it calls the notifyEnd method when it is on the 
last record.
Inside the notifyEnd method the ResultSet is closed.

If we take a look to the Foreach.java file we can see:

   protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
   {
     .....
     boolean hasNext = dataSource.hasNext();
     while (hasNext)
     {
       _value = dataSource.next();
       hasNext = dataSource.hasNext(); <<-- The ResultSet is closed when it 
gets the last record
       .....
       (some code using _value)      <<-- _value references a closed 
ResultSet !!
       .....
     }

The problem is resolved if we change that code with:

   protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
   {
     .....
     while (dataSource.hasNext())
     {
       _value = dataSource.next();
       .....
       (some code using _value)
       .....
     }

Somebody know a better solution?
Must be modified the Foreach component code?

Thanks for any suggestions,
   Julio.