Hej
I have a modalwindow where in there is a save button and a cancel button.
When i pres the cancel button i somehow need to know that this button has
been pressed.
I tried creating the modalpage as an inner class of the modal class, and in
that class editing a variable in the modal class. But when i return to the
modal class, all variables are unchanged.
Got any ideas?
package com.trifork.pengeplan.web.components.modal;
import com.trifork.pengeplan.domain.MoneyCurrency;
import com.trifork.pengeplan.web.components.CancelButton;
import
com.trifork.pengeplan.web.components.models.temporary.BankAccountModalObject;
import org.apache.wicket.Page;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.EnumChoiceRenderer;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
import java.beans.PropertyChangeSupport;
import java.util.Arrays;
/**
* @author
*/
public class AddBankAccountModal extends ModalWindow {
AddBankAccountModal self;
AddBankAccountModalPage modalPage;
DropDownChoice<Long> accountForCash;
protected PropertyChangeSupport propertyChangeSupport;
protected boolean saveButtonPressed;
public AddBankAccountModal(String id, final
IModel<BankAccountModalObject> model, final WebMarkupContainer
updateOnWindowsClosed) {
super(id);
self = this;
setPageCreator(new PageCreator() {
@Override
public Page createPage() {
return modalPage = new AddBankAccountModalPage(self, model);
}
});
setWindowClosedCallback(new WindowClosedCallback() {
public void onClose(AjaxRequestTarget target) {
if (saveButtonPressed) {
target.add(updateOnWindowsClosed);
}
saveButtonPressed = false;
}
});
setCloseButtonCallback(new CloseButtonCallback() {
public boolean onCloseButtonClicked(AjaxRequestTarget target) {
return true;
}
});
}
public void setAccountForCash(DropDownChoice<Long> accountForCash) {
this.accountForCash = accountForCash;
}
class AddBankAccountModalPage extends BaseModalPage {
public AddBankAccountModalPage(final AddBankAccountModal
modalWindow, IModel<BankAccountModalObject> model) {
super();
Form form = new Form("bankAccountForm", new
CompoundPropertyModel(model));
form.add(new TextField<String>("name").setRequired(true));
form.add(new
TextField<String>("financeAccount").setRequired(true));
form.add(new DropDownChoice<MoneyCurrency>("moneyCurrency",
Arrays.asList(MoneyCurrency.values()), new
EnumChoiceRenderer<MoneyCurrency>()).setRequired(true));
form.add(new AjaxButton("save", form) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?>
form) {
saveButtonPressed = true;
//TODO save new bank account with sub entities
modalWindow.close(target);
}
@Override
protected void onError(AjaxRequestTarget target, Form<?>
form) {
target.add(form.get("modalFeedback"));
}
});
CancelButton cancel = new CancelButton("cancel") {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?>
form) {
modalWindow.close(target);
}
};
form.add(cancel);
form.add(new
FeedbackPanel("modalFeedback").setOutputMarkupPlaceholderTag(true));
add(form);
}
}
}
Best regards
Tommy Sadiq Hinrichsen