I have created a palette in wicket and I'm able to populate the palette left side window. But I want to make the options in the palette are dynamic, able to do the same. But the problem is that the palette is not getting populate with selected options. I have a dropdown above the palette, depending on the option selected I want to populate the palette.
for example (dropdown(role) with values): 1.scenario: dropdown --> TL,Manager,SE,SSE pallete --> initially there will be no values, at the time of creating a role TL, there will be skill selected in the rite window of the palette. assume TL role is created with 4 skills outof 10 skills. 2.scenario: i want to edit the role TL, in this case when ever i choose the Role TL, the palette should get populate in such away that selected should be at right and available should be at left. i am failing in the second scenario.
Here is the code:
public class DropDownChoicePage extends WebPage {
private String selectedMake;
private final Map<String, List<String>> modelsMap = new HashMap<String, List<String>>();
private List<String> selected = new ArrayList<String>();
private String selectedEngine = "Google";
public DropDownChoicePage(final PageParameters parameters) {
add(new FeedbackPanel("feedback"));
modelsMap.put("AUDI", Arrays.asList(new String[] { "A4", "A6", "TT" }));
modelsMap.put("CADILLAC", Arrays.asList(new String[] { "CTS", "DTS", "ESCALADE", "SRX","DEVILLE" }));
modelsMap.put("FORD", Arrays.asList(new String[] { "CROWN", "ESCAPE", "EXPEDITION","EXPLORER", "F-150" }));
IModel<List<? extends String>> makeChoices = new AbstractReadOnlyModel<List<? extends String>>()
{
private static final long serialVersionUID = 1L;
@Override
public List<String> getObject()
{
Set<String> keys = modelsMap.keySet();
List<String> list = new ArrayList<String>(keys);
return list;
}
};
IModel<List<? extends String>> paletteChoices = new AbstractReadOnlyModel<List<? extends String>>(){
private static final long serialVersionUID = 1L;
@Override
public List<? extends String> getObject() {
List<String> models = modelsMap.get(selectedMake);
if (models == null)
{
models = Collections.emptyList();
}else if("FORD".equals(selectedMake)){
selected.add("CROWN");
selected.add("ESCAPE");
}
return models;
}
};
final DropDownChoice<String> makes = new DropDownChoice<String>("makes",new PropertyModel<String>(this, "selectedMake"), makeChoices);
IChoiceRenderer<String> renderer = new ChoiceRenderer<String>();
final Palette<String> palette = new Palette<String>("palette",
new ListModel<String>(selected),
paletteChoices,
renderer, 10, true);
palette.setOutputMarkupId(true);
makes.add(new AjaxFormComponentUpdatingBehavior("onchange")
{
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target)
{
selected = new ArrayList<String>();
target.addComponent(palette);
System.out.println("AjaxFormComponentUpdatingBehavior(\"onchange\")");
System.out.println("Selected Make:"+selectedMake);
}
});
Form<?> form = new Form<Void>("form") {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit() {
info("Selected search engine : " + selectedEngine);
selected = new ArrayList<String>();
}
};
add(form);
form.add(palette);
form.add(makes);
}
}
Can you please help me out in the second scenario,i.e populating both left and right windows of the palette with available and selected values on change event of the drop down.
thanks, Saran.