*/
@SuppressWarnings("unchecked")
@Override
protected void populateItem(ListItem<ISelectableTableViewPanelButtonProvider> item) {
final ISelectableTableViewPanelButtonProvider buttonProvider = item.getModelObject();
IFormOnSubmitAction buttonAction = buttonProvider
.getButtonAction();
if (buttonAction == null) {
Label label;
// not visible
item.add(label = new Label(BUTTON_ID));
label.setVisible(false);
item.add(label);
return;
}
// if the tow is required then
buttonAction = new AbstractFormOnSubmitAction() {
/**
*
*/
private static final long serialVersionUID = 5910571859628875165L;
public void onSubmit(AjaxRequestTarget target, Form form) {
if (buttonProvider.isSelectedRowRequired()) {
if (selectedContextField.getModelObject() == null) {
if (target != null) {
target.prependJavaScript("alert ('A selected row is required.');");
}
else
error("A selected row is required.");
return;
}
// fall through
}
// run the user logic
buttonProvider.getButtonAction().onSubmit(target, form);
// else the action is defined.
if (buttonProvider.isClearSelectedRowOnAction()) {
// clear the value in the form.
selectedContextField.clearInput();
}
}
};
DTAAjaxFallbackButton button;
// if (buttonProvider.isSelectedRowRequired()) {
//
// IModel<String> requireASelectedRow;
//
// final List<Radio>radioList = new LinkedList<Radio>();
//
// if (selectedContextField instanceof RadioGroup) {
// RadioGroup rg = (RadioGroup) selectedContextField;
//
// rg.visitChildren(new IVisitor() {
//
// /* (non-Javadoc)
// * @see org.apache.wicket.Component.IVisitor#component(org.apache.wicket.Component)
// */
// public Object component(Component component) {
//
// if (component instanceof Radio) {
//
// radioList.add((Radio) component);
// }
//
// return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
// }
//
// });
//
//
// requireASelectedRow = createRadioRequireSelectedRowModel (radioList);
//
// }
// else {
// // String hidden field
//
//
// requireASelectedRow = new MarkupIDInStringModel(
// "if (Wicket.$('" + MarkupIDInStringModel.MARKUP_ID_TAG
// + "').value == '') {"
// + "\nalert ('A selected row is required.');"
// + "\nreturn false;" + "}", selectedContextField);
// }
//
// button = new DTAAjaxFallbackButton(BUTTON_ID, buttonProvider
// .getButtonLabelText(displayEntityName), this.form,
// requireASelectedRow);
//
// button.setSubmitAction(buttonAction);
// }
// else {
button = new DTAAjaxFallbackButton(BUTTON_ID, buttonProvider
.getButtonLabelText(displayEntityName), this.form,
buttonAction);
// }
String cssClass = buttonProvider.getCSSClassName();
if (cssClass != null) {
button.add(new AttributeModifier("class", true, new Model<String>(cssClass)));
}