I created a palette which contains values, and i created a DropDownChoice ddcdomaines with an AjaxFormComponentUpdatingBehavior to update choice list, but i dont know how to do it, can you help me?
Here my code:
List<PartnerDomainDTO> domaines = partenaireHelper.allDomains();
ChoiceRenderer choiceRenderer = new ChoiceRenderer("label", "sid");
final Palette palette =
new Palette("partenaires", new PropertyModel(offre, "partenaires"), new Model(
(Serializable) partenairesPossibles), renderer, 10, false) {
private static final long serialVersionUID = 1178320215146881229L;
boolean first = true;
@Override
public Iterator getSelectedChoices() {
if (first) {
first = false;
return partenairesExistants.iterator();
}
return super.getSelectedChoices();
}
};
palette.setOutputMarkupId(true);
palette.setOutputMarkupPlaceholderTag(true);
DropDownChoice ddcdomaines = new DropDownChoice("domaines", new Model(domaines.get(0)), domaines, choiceRenderer);
ddcdomaines.add(new AjaxFormComponentUpdatingBehavior("onchange") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
remove(palette);
Palette palette1 =
new Palette(
"partenaires",
new PropertyModel(offre, "partenaires"),
new Model(new ArrayList<Partenaire>()),
renderer,
10,
false);
palette1.setOutputMarkupId(true);
palette1.setOutputMarkupPlaceholderTag(true);
add(palette1);
target.addComponent(palette);
target.addComponent(palette1);
}
});
add(palette);
add(ddcdomaines);
}
Here is an excellent example of DropDownChoice with AjaxFormComponentUpdatingBehavior:
http://wicketstuff.org/wicket/ajax/choice
Click on the Source Code link to see the source. If you need more information, than you need to provide more detail in your question.
Update: According to the JavaDoc, there is a specific way to update Palettes using Ajax:
http://wicket.apache.org/apidocs/1.4/org/apache/wicket/extensions/markup/html/form/palette/Palette.html
Make sure you follow those instructions before doing anything else.
In your code, you are attempting to remove one Palette and put in another Palette. While this might work in the long run, it is not very Wicket-y. Sadly, Palette does not have a public method to change the choices. However, if you keep a reference to your choicesModel, then you can modify that list and the Palette should see the change on re-render. Something like this:
And then in your Ajax onUpdate
Be careful with keeping track of the selected choices and the possible choices. I’m not sure what will happen if these don’t match up. Hope that helps!