JohnSmith333 wrote:
>
> I have use a Palette with DropDownChoice. I want to change the
> DropDownChoice's selected value and then update the Palette's lists. And
> when I click the Palette's value ,I hope to save the change result.
> But it's not work normally. Could anyone kind to help me? Thanks!
>
Your code contains quite a lot of bugs. Try this instead:
public class PaletteChoice extends WebPage implements Serializable {
private static final long serialVersionUID = 1L;
private Form form;
private DropDownChoice choice;
private Palette palette;
private Map mainMap = new HashMap();
private String mainChoice;
private Map availibleMap;
private Map selectedMap;
public PaletteChoice() {
availibleMap = new HashMap();
selectedMap = new HashMap();
// data
mainMap.put("A", "0");
mainMap.put("B", "1");
Set mainKeySet = mainMap.keySet();
Iterator it = mainKeySet.iterator();
while (it.hasNext()) {
Object ok = it.next();
ArrayList availibleList = new ArrayList();
for (int i = 0; i < 5; i++) {
availibleList.add(String.valueOf(ok) + i);
}
availibleMap.put(ok, availibleList);
List selectedList = new ArrayList();
selectedMap.put(ok, selectedList);
}
List mainList = new ArrayList();
Set tmpSet = mainMap.keySet();
Iterator tmpIt = tmpSet.iterator();
while (tmpIt.hasNext()) {
mainList.add((Serializable) tmpIt.next());
}
form = new Form("form", new CompoundPropertyModel(this));
form.setOutputMarkupId(true);
add(form);
choice = new DropDownChoice("mainChoice", mainList) {
protected void onSelectionChanged(java.lang.Object
newSelection) {
}
protected boolean wantOnSelectionChangedNotifications()
{
return true;
}
};
choice.setOutputMarkupId(true);
form.add(choice);
palette = new Palette("palette",
new PropertyModel(this, "selectedList"), new
PropertyModel(
this, "availibleList"), new
ChoiceRenderer("toString",
"toString"), 10, false);
palette.setOutputMarkupId(true);
palette.getRecorderComponent().add(
new AjaxFormSubmitBehavior(form, "onchange") {
protected void
onSubmit(AjaxRequestTarget target) {
target.addComponent(form);
}
});
form.add(palette);
}
public List getAvailibleList() {
return mainMap.containsKey(mainChoice) ? (List) availibleMap
.get(mainChoice) : Collections.EMPTY_LIST;
}
public void setAvailibleList(List availibleList) {
if (mainMap.containsKey(mainChoice)) {
availibleMap.put(mainChoice, availibleList);
}
}
public List getSelectedList() {
return mainMap.containsKey(mainChoice) ? (List) selectedMap
.get(mainChoice) : Collections.EMPTY_LIST;
}
public void setSelectedList(List selectedList) {
if (mainMap.containsKey(mainChoice)) {
selectedMap.put(mainChoice, selectedList);
}
}
public String getMainChoice() {
return mainChoice;
}
public void setMainChoice(String mainChoice) {
this.mainChoice = mainChoice;
}
}
--
View this message in context:
http://www.nabble.com/Question-about-use-Palette-with-DropDownChoice-tf4447817.html#a12738225
Sent from the Wicket - User mailing list archive at Nabble.com.