You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by sonoerin <hu...@yahoo.com> on 2011/03/22 19:50:04 UTC

how to populate SortableDataProvider

Hello everyone,

So I feel there is something I am overlooking in all my work on this.  I
have a Wicket 1.4/Spring2.5.6/hibernate 3.2/ app that I cannot get quite
right.  I have a SortableDataProvider that I am trying to populate by:

public class ABCTablePanel extends Panel {

  public ABCTablePanel (String id) {
    super(id);
    ABCProvider abcProvider = new ABCProvider();
    DefaultDataTable table = new DefaultDataTable("abctable", getColumns(),
abcProvider , 10);
    
    add(table);
  }

private List&lt;IColumn&lt;Abc&gt;> getColumns() {
      List&lt;IColumn&lt;Abc&gt;> result = new
ArrayList&lt;IColumn&lt;Abc&gt;>();     
      result.add( new PropertyColumn(new Model("Abc Description"),
"AbcDescription",
 "AbcDescription" ));
       result.add( new DatePropertyColumn(new Model("Abc Date"), AbcDate",
 "AbcDate" ));
...
 }

}


Then my provider:
public class AbcProvider extends SortableDataProvider {

private List list = new ArrayList( );
    private SortableDataProviderComparator comparator = new
SortableDataProviderComparator( );
    @SpringBean
    private AbcManager abcManager = null;

    public AbcProvider( ) {
        // The default sorting
        setSort( "abc.abcDescription", true );
    }

     public void refresh( List list ) {
        list.clear( );
        list.addAll( abcManager.getAllGaps( ) );
    }

    @Override
    public Iterator iterator( int first, int count ) {
        getAllAbcs( );  // method that calls a  manager, calling hibernate,
and populates "list"
        List newList = new ArrayList( list );

        // Sort the data
        Collections.sort( newList, comparator );

        // Return the data for the current page - this can be determined
only after sorting
        return newList.subList( first, first + count ).iterator( );

    }
    @Override
    public IModel model( final Abc object ) {        
        return new AbstractReadOnlyModel( ) {
            @Override
            public AbcgetObject( ) {
                return (Abc) object;
            }
        };
    }


When I run this all appears well, except the call is never made to populate
the table. I just get "No Records Found" beneath my column names, and the
debug points are never hit when I refresh or load the page.  

Thank you in advance for any help you can offer.



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-populate-SortableDataProvider-tp3397372p3397372.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: how to populate SortableDataProvider

Posted by Hans Lesmeister <ha...@lessy-software.de>.
Hi, shouldn't the provider implement a method count() which gives the  
total number of records?

Regards Hans

Am 22.03.2011 um 19:50 schrieb sonoerin <hu...@yahoo.com>:

> Hello everyone,
>
> So I feel there is something I am overlooking in all my work on  
> this.  I
> have a Wicket 1.4/Spring2.5.6/hibernate 3.2/ app that I cannot get  
> quite
> right.  I have a SortableDataProvider that I am trying to populate by:
>
> public class ABCTablePanel extends Panel {
>
>  public ABCTablePanel (String id) {
>    super(id);
>    ABCProvider abcProvider = new ABCProvider();
>    DefaultDataTable table = new DefaultDataTable("abctable",  
> getColumns(),
> abcProvider , 10);
>
>    add(table);
>  }
>
> private List&lt;IColumn&lt;Abc&gt;> getColumns() {
>      List&lt;IColumn&lt;Abc&gt;> result = new
> ArrayList&lt;IColumn&lt;Abc&gt;>();
>      result.add( new PropertyColumn(new Model("Abc Description"),
> "AbcDescription",
> "AbcDescription" ));
>       result.add( new DatePropertyColumn(new Model("Abc Date"),  
> AbcDate",
> "AbcDate" ));
> ...
> }
>
> }
>
>
> Then my provider:
> public class AbcProvider extends SortableDataProvider {
>
> private List list = new ArrayList( );
>    private SortableDataProviderComparator comparator = new
> SortableDataProviderComparator( );
>    @SpringBean
>    private AbcManager abcManager = null;
>
>    public AbcProvider( ) {
>        // The default sorting
>        setSort( "abc.abcDescription", true );
>    }
>
>     public void refresh( List list ) {
>        list.clear( );
>        list.addAll( abcManager.getAllGaps( ) );
>    }
>
>    @Override
>    public Iterator iterator( int first, int count ) {
>        getAllAbcs( );  // method that calls a  manager, calling  
> hibernate,
> and populates "list"
>        List newList = new ArrayList( list );
>
>        // Sort the data
>        Collections.sort( newList, comparator );
>
>        // Return the data for the current page - this can be  
> determined
> only after sorting
>        return newList.subList( first, first + count ).iterator( );
>
>    }
>    @Override
>    public IModel model( final Abc object ) {
>        return new AbstractReadOnlyModel( ) {
>            @Override
>            public AbcgetObject( ) {
>                return (Abc) object;
>            }
>        };
>    }
>
>
> When I run this all appears well, except the call is never made to  
> populate
> the table. I just get "No Records Found" beneath my column names,  
> and the
> debug points are never hit when I refresh or load the page.
>
> Thank you in advance for any help you can offer.
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-populate-SortableDataProvider-tp3397372p3397372.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: how to populate SortableDataProvider

Posted by sonoerin <hu...@yahoo.com>.
I tried changing that list to

   public void refresh( List list ) {
        list.clear( );
        this.list.addAll( abcManager.getAllGaps( ) );
    }

but that didn't seem to make a difference - but I could see how that would
update the wrong list if it was being called.

I can't help but think I have to do something with the DefaultDataTable
columns (even though I am not sure the provider is even being called) as I
am only doing this:

DefaultDataTable table = new DefaultDataTable("abctable", getColumns(),
abcProvider , 10); 
private List>  getColumns() {
        List Abc>>  result = new  ArrayList&lt;IColumn&amp;lt;Abc&gt;>();
        result.add( new PropertyColumn(new Model("Abc Description"), 
"AbcDescription", "AbcDescription" ));
         result.add( new DatePropertyColumn(new Model("Abc Date"), AbcDate",
"AbcDate" )); 


Does the DefaultDataTable  know how to populate each cell with the next
value in the Abc object its being populated?

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-populate-SortableDataProvider-tp3397372p3397546.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: how to populate SortableDataProvider

Posted by Sven Meier <sv...@meiers.net>.
Hi,

the following looks strange to me:

      public void refresh( List list ) {
         list.clear( );
         list.addAll( abcManager.getAllGaps( ) );
     }

Isn't there a "this" missing?

Sven

On 03/22/2011 07:50 PM, sonoerin wrote:
> Hello everyone,
>
> So I feel there is something I am overlooking in all my work on this.  I
> have a Wicket 1.4/Spring2.5.6/hibernate 3.2/ app that I cannot get quite
> right.  I have a SortableDataProvider that I am trying to populate by:
>
> public class ABCTablePanel extends Panel {
>
>    public ABCTablePanel (String id) {
>      super(id);
>      ABCProvider abcProvider = new ABCProvider();
>      DefaultDataTable table = new DefaultDataTable("abctable", getColumns(),
> abcProvider , 10);
>
>      add(table);
>    }
>
> private List&lt;IColumn&lt;Abc&gt;>  getColumns() {
>        List&lt;IColumn&lt;Abc&gt;>  result = new
> ArrayList&lt;IColumn&lt;Abc&gt;>();
>        result.add( new PropertyColumn(new Model("Abc Description"),
> "AbcDescription",
>   "AbcDescription" ));
>         result.add( new DatePropertyColumn(new Model("Abc Date"), AbcDate",
>   "AbcDate" ));
> ...
>   }
>
> }
>
>
> Then my provider:
> public class AbcProvider extends SortableDataProvider {
>
> private List list = new ArrayList( );
>      private SortableDataProviderComparator comparator = new
> SortableDataProviderComparator( );
>      @SpringBean
>      private AbcManager abcManager = null;
>
>      public AbcProvider( ) {
>          // The default sorting
>          setSort( "abc.abcDescription", true );
>      }
>
>       public void refresh( List list ) {
>          list.clear( );
>          list.addAll( abcManager.getAllGaps( ) );
>      }
>
>      @Override
>      public Iterator iterator( int first, int count ) {
>          getAllAbcs( );  // method that calls a  manager, calling hibernate,
> and populates "list"
>          List newList = new ArrayList( list );
>
>          // Sort the data
>          Collections.sort( newList, comparator );
>
>          // Return the data for the current page - this can be determined
> only after sorting
>          return newList.subList( first, first + count ).iterator( );
>
>      }
>      @Override
>      public IModel model( final Abc object ) {
>          return new AbstractReadOnlyModel( ) {
>              @Override
>              public AbcgetObject( ) {
>                  return (Abc) object;
>              }
>          };
>      }
>
>
> When I run this all appears well, except the call is never made to populate
> the table. I just get "No Records Found" beneath my column names, and the
> debug points are never hit when I refresh or load the page.
>
> Thank you in advance for any help you can offer.
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-populate-SortableDataProvider-tp3397372p3397372.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: how to populate SortableDataProvider

Posted by "robert.mcguinness" <ro...@gmail.com>.
http://apache-wicket.1842946.n4.nabble.com/Storing-ArrayList-with-over-10000-objects-td3343442.html#a3343499

Since then I followed Martijn's suggestion and cached the objects using the
Spring module @Cacheable annotation.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-populate-SortableDataProvider-tp3397372p3398102.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org