Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.apache.wicket.ajax.AjaxRequestTarget;
- import org.apache.wicket.ajax.markup.html.AjaxLink;
- 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.WebPage;
- import org.apache.wicket.markup.html.form.Form;
- import org.apache.wicket.markup.html.form.TextField;
- import org.apache.wicket.model.CompoundPropertyModel;
- import java.io.Serializable;
- public class FormTestPage extends WebPage {
- public FormTestPage() {
- }
- @Override
- protected void onInitialize() {
- super.onInitialize();
- add(new TheForm("TheForm", new CompoundPropertyModel<TestModel>(new TestModel())));
- }
- private class TheForm extends Form<TestModel> {
- public TheForm(String myForm, CompoundPropertyModel<TestModel> model) {
- super(myForm, model);
- TextField<String> textField = new TextField<String>("name");
- add(textField);
- textField.setRequired(true);
- final ModalWindow modalWindow = new ModalWindow("ModalWindow");
- add(modalWindow);
- add(new AjaxButton("AjaxButton", this) {
- @Override
- protected void onSubmit(AjaxRequestTarget target, Form form) {
- // process your model;
- xyz();
- // create the close link for the SuccessPanel
- AjaxLink closeLinkForSuccessPanel = createCloseLinkForSuccessPanel(modalWindow);
- // set the Content
- modalWindow.setContent(new SuccessPanel(ModalWindow.CONTENT_ID, closeLinkForSuccessPanel));
- // set the call back
- modalWindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
- @Override
- public void onClose(AjaxRequestTarget target) {
- setResponsePage(new AnyPage());
- }
- });
- // show the panel
- modalWindow.show(target);
- }
- });
- }
- }
- private AjaxLink createCloseLinkForSuccessPanel(final ModalWindow modalWindow) {
- return new AjaxLink("close") {
- @Override
- public void onClick(AjaxRequestTarget target) {
- modalWindow.close(target);
- }
- };
- }
- }
- //
- //
- //
- public class TestModel implements Serializable {
- private String name;
- public TestModel() {
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- }
- //
- // FormTestPage.html
- //
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml"
- xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd"
- xml:lang="fr" lang="fr">
- <body>
- <form wicket:id="TheForm">
- <span style="display: none;" wicket:id="ModalWindow"></span>
- <input wicket:id="name" type="text" size="40">
- <input wicket:id="AjaxButton" type="submit" value="submit"/>
- </form>
- </body>
- </html>
- //
- //
- //
- public class SuccessPanel extends Panel {
- public SuccessPanel(String wid, AjaxLink closeLinkForSuccessPanel) {
- super(wid);
- add( closeLinkForSuccessPanel );
- }
- }
- //
- // SuccessPanel.html
- //
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml"
- xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd"
- xml:lang="fr" lang="fr">
- <wicket:panel>
- success
- <br>
- <a wicket:id="close">close</a>
- </wicket:panel>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement