I solved the problem by creating custom add and remove buttons. It turned out
that the original buttons that are used by Palette are not subclasses of
Button but subclasses of WebMarkupContainer and hence they don't properly
support disabled state and generating of markup id. I wonder why plain
buttons were not used. Now I use the following subclass and it works just
fine:
[code]
private class PupilPalette extends Palette {
private static final long serialVersionUID =
6962784629546969362L;
private Button addButton;
private Button removeButton;
public PupilPalette(final String id, final IModel model,
final IModel choicesModel, final
IChoiceRenderer choiceRenderer,
final int rows, final boolean allowOrder) {
super(id, model, choicesModel, choiceRenderer, rows,
allowOrder);
setOutputMarkupId(true);
getRecorderComponent().add(new
AjaxFormComponentUpdatingBehavior("onchange") {
private static final long serialVersionUID =
-1322527042794395640L;
@Override
protected void onUpdate(final AjaxRequestTarget
target) {
checkButtonsEnabled();
target.addComponent(addButton);
target.addComponent(removeButton);
}
});
checkButtonsEnabled();
}
/**
* Checks whether the add or remove buttons are enabled.
*/
private void checkButtonsEnabled() {
addButton.setEnabled(availablePupils.size() !=
selectedPupils.size());
removeButton.setEnabled(!selectedPupils.isEmpty());
}
/** [EMAIL PROTECTED] */
@Override
protected Component newAvailableHeader(final String
componentId) {
return new Label(componentId,
getString("available.pupils"));
}
/** [EMAIL PROTECTED] */
@Override
protected Component newSelectedHeader(final String componentId)
{
return new Label(componentId,
getString("selected.pupils"));
}
/** [EMAIL PROTECTED] */
@Override
protected Component newAddComponent() {
addButton = new Button("addButton", new Model("->")) {
private static final long serialVersionUID = 0L;
protected void onComponentTag(final
ComponentTag tag) {
super.onComponentTag(tag);
tag.getAttributes().put("onclick",
PupilPalette.this.getAddOnClickJS());
}
};
addButton.add(new Image("image", new
ResourceReference(Palette.class,
"add.gif")));
addButton.setOutputMarkupId(true);
return addButton;
}
/** [EMAIL PROTECTED] */
@Override
protected Component newRemoveComponent() {
removeButton = new Button("removeButton") {
private static final long serialVersionUID = 1L;
protected void onComponentTag(final
ComponentTag tag) {
super.onComponentTag(tag);
tag.getAttributes().put("onclick",
PupilPalette.this.getRemoveOnClickJS());
}
};
removeButton.add(new Image("image", new
ResourceReference(Palette.class,
"remove.gif")));
removeButton.setOutputMarkupId(true);
return removeButton;
}
}
[/code]
wheleph
--
View this message in context:
http://www.nabble.com/Disabling-Palette-buttons-tf4732206.html#a13545250
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]