Gunna, First of all, thank you very much for your help. But unfortunatelly, as you said in the last paragraph of your email (if I understood you correctly), you only show keys in your selected list, while I must show both keys and labels.
I am still trying to make my model fit the selected list, but I'll get there. This Palette is a tricky fellow... On 6/19/06, Gunna Satria <[EMAIL PROTECTED]> wrote:
Hi Rui, I try to simulate your problem, here is my working code. Hope there's no miss perception here.. here is my CustomModel, import org.apache.tapestry.form.IPropertySelectionModel; public class CustomModel implements IPropertySelectionModel{ private String[] keys = {"G","S","H","K"}; private String[] values = {"Gunna","Satria","Hijrah","Kusumah"}; public CustomModel(){ } /* (non-Javadoc) * @see org.apache.tapestry.form.IPropertySelectionModel#getOptionCount() */ public int getOptionCount() { return keys.length; } /* (non-Javadoc) * @see org.apache.tapestry.form.IPropertySelectionModel#getOption (int) */ public Object getOption(int arg0) { return keys[arg0]; } /* (non-Javadoc) * @see org.apache.tapestry.form.IPropertySelectionModel#getLabel(int) */ public String getLabel(int arg0) { return values[arg0]; } /* (non-Javadoc) * @see org.apache.tapestry.form.IPropertySelectionModel#getValue(int) */ public String getValue(int arg0) { return keys[arg0]; } /* (non-Javadoc) * @see org.apache.tapestry.form.IPropertySelectionModel#translateValue( java.lang.String) */ public Object translateValue(String arg0) { int index = 0; for (int i = 0; i < keys.length; i++) { if(arg0.equals(keys[i])){ index = i; break; } } return values[index]; } } here is my code in page class providing selected list and the model, public IPropertySelectionModel getModel(){ return new CustomModel(); } public List getSelected(){ List list = new ArrayList(); list.add("S"); //list content is amongs keys array defined in CustomModel list.add("H"); return list; } the problem is maybe in the content of your selected id list, it is really same as in the one you define in the model. In my simple case, selected list filled with "G","S","H", or "K" not with "Gunna", "Satria" etc. cheers, Gunna Rui Pacheco <[EMAIL PROTECTED]> wrote: I think I'm having problems because I use a custom model for my PropertySelection and Palette. I am using a model that has both values and labels, the values being defined not by the position of the label on the drop down but by an ID that I fetch from the database. The content of that model is a type I defined as an interface with getters and setters for an int and a String, Now, I tried setting the selected elements of my Palette with both a List of the inner class that holds the values for my model and a List of models, each with only one value. Neither worked. Can anyone help me with this one? Many thanks, Rui On 6/15/06, Schulte Marcus wrote: > > I'll try: > > You have an implementation of IPropertySelectionModel, getOption(int) > returns some Object from your domain model, say of class A. > So the "model" parameter is boud to the IPropertySelectionModel. > Then you bind the "selected" parameter to a collection of A (e.g. > List). > > Now Palette determines whether an object a of class A should be shown on > the > "selected" side of things by testing for something like selected.contains( > a > ). > > Therefore, class A must override Object.equals() if you don't work with > the > very same instances of A in the IPropertySelectionModel and the > selected-list. > > To be more specific about this I'd have to know about exactly how your > selected-List and your IPropertySelectionModel are populated > > hth Marcus > > > -----Original Message----- > > From: Rui Pacheco [mailto:[EMAIL PROTECTED] > > Sent: Thursday, June 15, 2006 1:13 AM > > To: Tapestry users > > Subject: Re: Setting selected values on Palette > > > > Hi Marcus > > > > Could you please explain what do you mean by that? > > > > On 6/14/06, Rui Pacheco wrote: > > > > > > > Just be sure that modelObj.equals( selectedObj ) returns > > true when > > > > it > > > should. > > > > > > What do you mean? The object that I pass to the selected parameter > > > should be the same as the model? But the documentation mentions a > > > List. Should I pass a List of models, then? > > > > > > > > > > > > On 6/14/06, Schulte Marcus wrote: > > > > > > > > You can use any collection of Model-objects (the objects > > which are > > > > returned by getOption(int) from your PropertySelectionModel). > > > > > > > > Just be sure that modelObj.equals( selectedObj ) returns > > true when > > > > it should. > > > > Marcus > > > > > > > > > -----Original Message----- > > > > > From: Rui Pacheco [mailto:[EMAIL PROTECTED] > > > > > Sent: Wednesday, June 14, 2006 2:05 PM > > > > > To: Tapestry users; Tapestry users > > > > > Subject: Setting selected values on Palette > > > > > > > > > > My little project moves on. I started with a select > > from which I > > > > > needed to retrieve multiple values, now things have > > changed (damn > > > > > the spec, we don't need no stinkin' specs!) and I ended > > up using a > > > > > Palette. > > > > > > > > > > Which brings us to my question: I have no problem setting the > > > > > model and retrieving the selected values. But how can I set the > > > > > selected values if, say, I wanted to edit the information on my > > > > > form instead of filling a new form? > > > > > > > > > > I tried passing a List of models (same type as the models I'm > > > > > using to fill the Palette's model), and a simple list with > > > > > Strings, but nothing happens. > > > > > -- > > > > > Cumprimentos, > > > > > Rui Pacheco > > > > > > > > > > > > > > > -------------------------------------------------------------------- > > > > - To unsubscribe, e-mail: [EMAIL PROTECTED] > > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > > > > > > > > > -- > > > Cumprimentos, > > > Rui Pacheco > > > > > > > > > > > -- > > Cumprimentos, > > Rui Pacheco > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- Cumprimentos, Rui Pacheco --------------------------------- Ring'em or ping'em. Make PC-to-phone calls as low as 1ยข/min with Yahoo! Messenger with Voice.
-- Cumprimentos, Rui Pacheco