Ok I think I am understanding it a little better now.
For now Im still extending myDataProvider  from ListDataProvider, but no
longer using  a new ArrayList() for every search. Im clearing it out and
adding new data, which is okay.

One question though -- What is the responsibility scope of the
ListDataProvider / IDataProvider?

Am I correct in assuming the following --

1) only operate on the given List/Data (already manipulated)
2) *should not* contain a Dao, and refresh its own list/data.

Because if (2), then I am seeing an issue -- where do I call the dao.query()
? In the constructor or in the iterator() ? If I do in the constructor, its
not refreshed for further queries. If I do in the iterator(), then the
size() is queried before the DataView calls the  iterator(), so it always
returns 0 records for the first time. And also calling dao.query() in the
iterator() will make it query the whole list for every pagination, which is
probably not a good idea.

I liked the idea of dataprovider encapsulating dao, but not clear where
would I refresh it.
Thanks !
Vasya

On Tue, May 26, 2009 at 3:25 PM, Igor Vaynberg <[email protected]>wrote:

> i meant implement IDataProvider directly if ListDataProvider doesnt
> work for you. most of the time you modify an existing instance of
> List, not create a new one, so ListDataProvider is useful there.
>
> -igor
>
> On Tue, May 26, 2009 at 1:15 PM, Vasu Srinivasan <[email protected]>
> wrote:
> > Thanks for the reply ...
> >
> > I tried doing this :
> > class MyDataProvider extends  ListDataProvider {
> >
> >  DataDao dataDao;
> >  Criteria criteria;
> >
> >  public MyDataProvider(List list, Criteria criteria) {
> >      super(list);
> >       ...
> >  }
> >
> >  //providing my own iterator which goes to the dataDao and gets the data
> >  //But now I cannot set the list, because private... So I have to use my
> > own list member...If I do that, then what is the point of calling the
> > constructor with List?
> > }
> >
> > Looks like ListDataProvider is not useful for reusable Lists. Not sure
> why
> > this should be so ? If I am able to set a new List into the provider, I
> > would not be breaking anything because the data is anyway retrieved only
> via
> > an Iterator.
> >
> > The problem is even if I create a new ListDataProvider for every new
> list, I
> > am not able to set that again in my data view. DataView does not have any
> > thing similar to setList (a la ListView.setList). I dont think I should
> be
> > creating a new DataView for every search, because all i'm doing is only
> > changing contents of the underlying list.
> >
> > Am I missing something ?
> >
> >
> > On Tue, May 26, 2009 at 12:29 PM, Igor Vaynberg <[email protected]
> >wrote:
> >
> >> you can build your own analog of listdataprovider that pulls the list
> >> directly from whatever property contains the latest.
> >>
> >> -igor
> >>
> >> On Tue, May 26, 2009 at 9:38 AM, Vasu Srinivasan <[email protected]>
> >> wrote:
> >> > Hello:
> >> > I have a simple search form , where some criteria refreshes the table
> >> based
> >> > on the db. I got it working with ListView, but im trying to use
> >> > ListDataProvider, I feel missing something:
> >> >
> >> > class MyForm {
> >> >  List myList;
> >> >  MyDataView myDataView;
> >> >  MyDataProvider myDataProvider;
> >> >
> >> >  public MyForm() {
> >> >    @Override public void onSubmit() {
> >> >       myList  = refreshData(criteria);
> >> >       //Question: How do I set this list into the myDataView or
> >> > myDataProvider ? I thought myDataView or the provider will auto pick
> it
> >> up,
> >> > because its a member variable and is a RefreshingView
> >> >    }
> >> >
> >> >    //First time
> >> >    myList = refreshData(defaultCriteria);
> >> >    myDataView = new MyDataView("myDataView" , new
> >> MyDataProvider(myList));
> >> >    add(myListView);
> >> >  }
> >> > }
> >> >
> >> >
> >> > class MyDataView extends DataView {
> >> >   public MyDataView(String id, IDataProvider provider) { super(id,
> >> > provider); }
> >> >
> >> >   @Override public void populateItem(Item item) { .... }
> >> > }
> >> >
> >> > class MyDataProvider extends ListDataProvider {
> >> >  public MyDataProvider(List list) {
> >> >     super(list);
> >> >  }
> >> > }
> >> >
> >> > I looked at the example that uses ListView
> >> > http://cwiki.apache.org/WICKET/reading-from-a-database.html
> >> > <http://cwiki.apache.org/WICKET/reading-from-a-database.html>
> >> >
> >> > With ListView it works fine if I do this in the method onSubmit()
> >> >
> >> > myList = refreshData(criteria);
> >> > myListView.setList(myList);
> >> >
> >> > But with DataView, I do not have a set method to reset the new list
> >> obtained
> >> > based on the criteria. The db returns correct data, but the page
> displays
> >> > the old data (no change). Neither do I see a method to set the new
> list
> >> in
> >> > the ListDataProvider.
> >> >
> >> > I even tried adding a new view inside the onSubmit, but that doesnt
> work
> >> > either:
> >> >
> >> > myDataView = new MyDataView("myDataView", new
> MyDataProvider(newList));
> >> >
> >> > --
> >> > Thanks!
> >> > Vasu Srinivasan
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [email protected]
> >> For additional commands, e-mail: [email protected]
> >>
> >>
> >
> >
> > --
> > Regards,
> > Vasu Srinivasan
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>


-- 
Regards,
Vasu Srinivasan

Reply via email to