Repository: wicket Updated Branches: refs/heads/wicket-6.x dfd12188a -> fc988d890
WICKET-2542 provide ajaxified buttons for wizards Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/fc988d89 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/fc988d89 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/fc988d89 Branch: refs/heads/wicket-6.x Commit: fc988d890a903ce0e0ea92c68b3a57653a154094 Parents: dfd1218 Author: svenmeier <[email protected]> Authored: Wed Feb 26 15:36:33 2014 +0100 Committer: svenmeier <[email protected]> Committed: Wed Feb 26 15:36:33 2014 +0100 ---------------------------------------------------------------------- .../wicket/examples/wizard/NewUserWizard.java | 14 +++ .../extensions/wizard/AjaxWizardButtonBar.java | 117 +++++++++++++++++++ 2 files changed, 131 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/fc988d89/wicket-examples/src/main/java/org/apache/wicket/examples/wizard/NewUserWizard.java ---------------------------------------------------------------------- diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/wizard/NewUserWizard.java b/wicket-examples/src/main/java/org/apache/wicket/examples/wizard/NewUserWizard.java index c40e157..48f7b4d 100644 --- a/wicket-examples/src/main/java/org/apache/wicket/examples/wizard/NewUserWizard.java +++ b/wicket-examples/src/main/java/org/apache/wicket/examples/wizard/NewUserWizard.java @@ -19,6 +19,8 @@ package org.apache.wicket.examples.wizard; import java.util.Arrays; import java.util.List; +import org.apache.wicket.Component; +import org.apache.wicket.extensions.wizard.AjaxWizardButtonBar; import org.apache.wicket.extensions.wizard.StaticContentStep; import org.apache.wicket.extensions.wizard.Wizard; import org.apache.wicket.extensions.wizard.WizardModel; @@ -46,11 +48,14 @@ import org.apache.wicket.validation.validator.EmailAddressValidator; * domain object ({@link User}) as it's subject. Also, the user roles step}is an optional step, that * will only be executed when assignRoles is true (and that value is edited in the user details * step). + * <br> + * Buttons are using Ajax requests. * * @author Eelco Hillenius */ public class NewUserWizard extends Wizard { + /** * The confirmation step. */ @@ -202,6 +207,15 @@ public class NewUserWizard extends Wizard } /** + * Use Ajax buttons. + */ + @Override + protected Component newButtonBar(String id) + { + return new AjaxWizardButtonBar(id, this); + } + + /** * Gets user. * * @return user http://git-wip-us.apache.org/repos/asf/wicket/blob/fc988d89/wicket-extensions/src/main/java/org/apache/wicket/extensions/wizard/AjaxWizardButtonBar.java ---------------------------------------------------------------------- diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/wizard/AjaxWizardButtonBar.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/wizard/AjaxWizardButtonBar.java new file mode 100644 index 0000000..bdcb9b6 --- /dev/null +++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/wizard/AjaxWizardButtonBar.java @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.wicket.extensions.wizard; + +import org.apache.wicket.Component; +import org.apache.wicket.MarkupContainer; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.attributes.AjaxRequestAttributes; +import org.apache.wicket.ajax.form.AjaxFormSubmitBehavior; + +/** + * A bar of buttons for wizards utilizing {@link AjaxFormSubmitBehavior}. + * + * @see Wizard#newButtonBar(String) + * + * @author svenmeier + */ +public class AjaxWizardButtonBar extends WizardButtonBar +{ + private static final long serialVersionUID = 1L; + + /** + * Construct. + * + * @param id + * The component id + * @param wizard + * The containing wizard + */ + public AjaxWizardButtonBar(String id, Wizard wizard) + { + super(id, wizard); + + wizard.setOutputMarkupId(true); + } + + @Override + public MarkupContainer add(Component... childs) + { + for (Component component : childs) + { + if (component instanceof WizardButton) + { + ajaxify((WizardButton)component); + } + } + return super.add(childs); + } + + private void ajaxify(final WizardButton button) + { + button.add(new AjaxFormSubmitBehavior("click") + { + private static final long serialVersionUID = 1L; + + @Override + protected void updateAjaxAttributes(AjaxRequestAttributes attributes) + { + super.updateAjaxAttributes(attributes); + + AjaxWizardButtonBar.this.updateAjaxAttributes(attributes); + } + + @Override + public boolean getDefaultProcessing() + { + return button.getDefaultFormProcessing(); + } + + @Override + protected void onSubmit(AjaxRequestTarget target) + { + target.add(findParent(Wizard.class)); + + button.onSubmit(); + } + + @Override + protected void onAfterSubmit(AjaxRequestTarget target) + { + button.onAfterSubmit(); + } + + @Override + protected void onError(AjaxRequestTarget target) + { + target.add(findParent(Wizard.class)); + + button.onError(); + } + }); + } + + /** + * Hook method to update Ajax attributes. + * + * @param attributes + * Ajax attributes + */ + protected void updateAjaxAttributes(AjaxRequestAttributes attributes) + { + } +} \ No newline at end of file
