The id of the dataitem needs to be the primary key of your object. This is
how the listview knows if it already created a dataitem for an object, if we
use an arbitrary counter we lose that knowledge.

As far as compound keys go, just create a unique string rep of the key:

public class MyCompoundKey implements Serializable {
        private long part1;
        private String part2;
        .....
}

public class MyDataProvider implements IDataProvider {
        public String primaryKey(Object object) {
                return
object.getId().getPart1()+"-"+object.getId().getPart2();
        }
        .....
}


-Igor


> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of 
> Christian Essl
> Sent: Tuesday, August 09, 2005 6:44 PM
> To: [email protected]
> Subject: Re: [Wicket-user] DataView
> 
> Why does it need the primary-key string? I think you could 
> make the id of DataItem through an up-counting long in 
> DataView. This should give enough ids for any reasonable 
> user-session - if not start with 0, risk a (now very 
> unlikely) exception catch it and start over with a random seed.
> 
> Instead of using a Set in internalOnBeginRequest() use a Map 
> and map from Model to DataItem and get the (generated) id this way.
> 
> I think removing the primaryKey() method would make the impl 
> easier and would help in cases where you do not have a 
> straight primary key like with compound keys, generated data 
> or even not deterministic generated data.
> 
> Christian
> 
> On Tue, 9 Aug 2005 15:04:59 -0700, Phil Kulak 
> <[EMAIL PROTECTED]> wrote:
> 
> > The DataView needs a string representation of the primary 
> key. I guess 
> > you could require that IModels in a data view override 
> toString() to 
> > return a string representation of the primary key. However, if you 
> > didn't do that, it would be a terrible bug to track down if 
> you were 
> > new to Wicket, or even if you weren't. I think that having a
> > getPrimaryKey() method just makes it self documenting, even if you 
> > just delegate to to a toString() on your model.
> >
> > I agree about the set with all those contains() operations.
> >
> > On 8/9/05, Christian Essl <[EMAIL PROTECTED]> wrote:
> >> Hi,
> >>
> >> I was just going through the new source of DataView and have a few 
> >> questions (good work Igor):
> >>
> >> Quite minor but I think it would be better to use a Set 
> than List for 
> >> existingKeys in DataView.internalOnBeginRequest().
> >>
> >> Is IDataProvider.primaryKey() realy needed? Why can't the 
> IModel be 
> >> used as the key. The IModel is stored in DataItem as is the id and 
> >> than the IModel should know best wheter the Object it 
> refers to is equal or not.
> >> In
> >> case of a lazy Model it will hold the primaryKey anway and 
> in other 
> >> cases it can delegate its equals/hashCode to the wrapped Object.
> >>
> >> Does DataItem have to be a public Component? I think of something 
> >> like
> >> this:
> >>
> >> class DataView{
> >>
> >>     private DataItem _currentItem = null;
> >>
> >>     void internalOnBeginRequest(){
> >>       ...
> >>       //when a new DataItem is needed
> >>       DataItem item = newItem(...);
> >>       super.add(item);
> >>       try{
> >>         _currentItem = item;
> >>          populateItem(index,model);
> >>       }finally{
> >>        _currentItem = null;
> >>       }
> >>     }
> >>
> >>     public void add(Component child){
> >>         if(_currentItem == null)
> >>             throw new IllegalStateException();
> >>         _currentItem.add(comp);
> >>     }
> >>
> >>     //use normal DataView.add() in here
> >>     abstract void populateItem(int index,IModel model);
> >>
> >> }
> >>
> >> I do not know if this is good, but I think it could make the api a 
> >> bit smaller and prevent a common pitfall to add items to 
> the DataView 
> >> directly.
> >>
> >> Christian
> >>
> >>
> >>
> >> --
> >> Christian Essl
> >>
> >>
> >>
> >>
> >>
> >> ___________________________________________________________
> >> Gesendet von Yahoo! Mail - Jetzt mit 1GB Speicher kostenlos - Hier
> >> anmelden: http://mail.yahoo.de
> >>
> >>
> >>
> >> -------------------------------------------------------
> >> SF.Net email is Sponsored by the Better Software Conference & EXPO 
> >> September 19-22, 2005 * San Francisco, CA * Development Lifecycle 
> >> Practices Agile & Plan-Driven Development * Managing 
> Projects & Teams 
> >> * Testing & QA Security * Process Improvement & Measurement * 
> >> http://www.sqe.com/bsce5sf 
> >> _______________________________________________
> >> Wicket-user mailing list
> >> [email protected]
> >> https://lists.sourceforge.net/lists/listinfo/wicket-user
> >>
> >
> >
> > -------------------------------------------------------
> > SF.Net email is Sponsored by the Better Software Conference & EXPO 
> > September 19-22, 2005 * San Francisco, CA * Development Lifecycle 
> > Practices Agile & Plan-Driven Development * Managing 
> Projects & Teams 
> > * Testing & QA Security * Process Improvement & Measurement * 
> > http://www.sqe.com/bsce5sf 
> > _______________________________________________
> > Wicket-user mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/wicket-user
> 
> 
> 
> --
> Christian Essl 
> 
>       
> 
>       
>               
> ___________________________________________________________
> Gesendet von Yahoo! Mail - Jetzt mit 1GB Speicher kostenlos - 
> Hier anmelden: http://mail.yahoo.de
> 
> 
> 
> -------------------------------------------------------
> SF.Net email is Sponsored by the Better Software Conference & EXPO
> September 19-22, 2005 * San Francisco, CA * Development 
> Lifecycle Practices
> Agile & Plan-Driven Development * Managing Projects & Teams * 
> Testing & QA
> Security * Process Improvement & Measurement * 
> http://www.sqe.com/bsce5sf
> _______________________________________________
> Wicket-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/wicket-user
> 
> 
> 




-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to