Dan wrote:
> hmm..i dont recognize the link though, between overriding equals and
> initializing the selected List ?
> maybe i m not on the same page as u :( i assume u r referring to
> overriding equals of the objects(model) inside the list? if thats the
> case, i already ve done that. could you please elaborate more?
So, you've got your palette component...
parameter: selected, and model...
model contains the list of all possible selected values, right?
So... using the ListPropertySelectionModel, I'll put together a quick
example... something like:
public class User {
public List getSpokenLanguages() {
...
}
public void addToSpokenLanguages(Language l) {
getSpokenLanguages().add(l);
}
...
}
public class Language implements NamedListItem {
private String name;
public String getItemName() {
return name;
}
public Language(String name) {
this.name=name;
}
}
template:
...
<select jwcid="@contrib:Palette"
selected="ognl:visit.user.spokenLanguages" model="ognl:languageModel"/>
page.java:
...
IPropertySelectionModel languageModel=null;
public IPropertySelectionModel getLanguageModel() {
if (languageModel == null) {
List languages = new ArrayList();
languages.add(new Language("English"));
languages.add(new Language("French"));
languages.add(new Language("Japanese"));
}
return languageModel;
}
So... then the question is... suppose that you need to have some
languages preselected...
The first key is to have those languages in the list returned by
"getSpokenLanguages". Now, suppose that you know that every user
of your particular system at least speaks english, so, in your init
code for the user, you do something like:
this.addToSpokenLanguages(new Language("English"));
Now when you hit the palette page, "English" will NOT be in the selected
page still. Because the "English" instance in the "SpokenLanguages"
list is different than the instance in the model. So, the second
key is to make sure that equals returns true when it should.
(Or else, the second key is to ensure that the instances actually are
the same. :)
So, going back to the language class...
public class Language ... {
...
public boolean equals(Object o) {
return o!=null && o instanceof Language &&
((Language)o).getItemName().equals(this.name);
}
}
With that addition, and with the bit of init code above (add english to
the spoken language list), then when you hit the page with the palette
component, "English" will be selected.
Robert
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]