Repository: wicket Updated Branches: refs/heads/master b6db8d977 -> 084d3e1b2
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/084d3e1b Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/084d3e1b Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/084d3e1b Branch: refs/heads/master Commit: 084d3e1b25c339a8ac6562b6f8175499faea1eb8 Parents: b6db8d9 Author: svenmeier <[email protected]> Authored: Wed Feb 26 15:36:55 2014 +0100 Committer: svenmeier <[email protected]> Committed: Wed Feb 26 15:36:55 2014 +0100 ---------------------------------------------------------------------- .../wicket/examples/wizard/NewUserWizard.java | 13 +++ .../extensions/wizard/AjaxWizardButtonBar.java | 117 +++++++++++++++++++ 2 files changed, 130 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/084d3e1b/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 7478899..139392e 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,6 +48,8 @@ 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 */ @@ -202,6 +206,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/084d3e1b/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
