Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

datatable-autocomplete changes: support onError

When using an AjaxButton for example and the form does not submit due to
validation errors there is an onError(target, form) that needs to be
implemented.

These changes add in a new method on the renamed IFormSubmitAction to support
handling the onError case.  It is connected to the DTAButton.onError()
callback.

git-svn-id: file:///home/igor/dev/stuff/svnbackup/branches/wicketstuff-core-1.4@5683 ef7698a4-5110-0410-9fc6-c7eb3693863f
  • Loading branch information...
commit eb6f98032084609e41f4373a4e0fb3be5b29bd23 1 parent 72d83f1
Michael O'Cleirigh authored mocleiri committed
View
23 ...able-autocomplete/src/main/java/org/wicketstuff/datatable_autocomplete/button/DTAAjaxFallbackButton.java
@@ -27,7 +27,7 @@
import org.apache.wicket.model.Model;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.wicketstuff.datatable_autocomplete.form.action.IFormOnSubmitAction;
+import org.wicketstuff.datatable_autocomplete.form.action.IFormSubmitAction;
/**
* @author mocleiri
@@ -53,7 +53,7 @@
private static final Logger log = LoggerFactory
.getLogger(DTAAjaxFallbackButton.class);
- private IFormOnSubmitAction submitAction = null;
+ private IFormSubmitAction submitAction = null;
private IAjaxCallDecorator ajaxCallDecorator = null;
@@ -124,7 +124,7 @@ public void setActionDeterminesVisibility(boolean actionDeterminesVisibility) {
* @param id
*/
public DTAAjaxFallbackButton(String id, String label, Form form,
- IFormOnSubmitAction submitAction) {
+ IFormSubmitAction submitAction) {
super(id, new Model(label), form);
this.form = form;
@@ -197,6 +197,21 @@ protected final void onSubmit(AjaxRequestTarget target, Form form) {
submitAction.onSubmit(target, form);
}
+
+
+
+ /* (non-Javadoc)
+ * @see org.apache.wicket.ajax.markup.html.form.AjaxFallbackButton#onError(org.apache.wicket.ajax.AjaxRequestTarget, org.apache.wicket.markup.html.form.Form)
+ */
+ @Override
+ protected void onError(AjaxRequestTarget target, Form<?> form) {
+
+ callCounter++;
+
+ if (submitAction != null)
+ submitAction.onError(target, form);
+
+ }
/*
* (non-Javadoc)
@@ -241,7 +256,7 @@ protected void onBeforeRender() {
* @param submitAction
* the submitAction to set
*/
- public void setSubmitAction(IFormOnSubmitAction submitAction) {
+ public void setSubmitAction(IFormSubmitAction submitAction) {
this.submitAction = submitAction;
}
View
8 ...parent/datatable-autocomplete/src/main/java/org/wicketstuff/datatable_autocomplete/button/DTAButton.java
@@ -20,7 +20,7 @@
import org.apache.wicket.model.Model;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.wicketstuff.datatable_autocomplete.form.action.IFormOnSubmitAction;
+import org.wicketstuff.datatable_autocomplete.form.action.IFormSubmitAction;
/**
@@ -38,14 +38,14 @@
private static final Logger log = LoggerFactory.getLogger(DTAButton.class);
- private IFormOnSubmitAction submitAction = null;
+ private IFormSubmitAction submitAction = null;
/**
* @param id
*/
- public DTAButton(String id, String label, IFormOnSubmitAction submitAction) {
+ public DTAButton(String id, String label, IFormSubmitAction submitAction) {
super(id, new Model<String> (label));
@@ -100,7 +100,7 @@ public void onSubmit() {
/**
* @param submitAction the submitAction to set
*/
- public void setSubmitAction(IFormOnSubmitAction submitAction) {
+ public void setSubmitAction(IFormSubmitAction submitAction) {
this.submitAction = submitAction;
}
View
108 ...ocomplete/src/main/java/org/wicketstuff/datatable_autocomplete/form/action/AbstractFormSubmitAction.java
@@ -0,0 +1,108 @@
+/*
+ *
+ * ==============================================================================
+ * Licensed 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.wicketstuff.datatable_autocomplete.form.action;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.markup.html.form.Form;
+
+/**
+ * @author mocleiri
+ *
+ * A base IFormSubmitAction implementation that supports a common case where a single container needs to be updated via ajax for either a
+ * successful submit or error case.
+ *
+ */
+public abstract class AbstractFormSubmitAction<T> implements IFormSubmitAction<T> {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -9039664701112891380L;
+ private final Component onUpdateComponent;
+
+
+ /**
+ *
+ */
+ public AbstractFormSubmitAction(Component onUpdateComponent) {
+ this.onUpdateComponent = onUpdateComponent;
+
+ }
+
+ /**
+ *
+ */
+ public AbstractFormSubmitAction() {
+ this (null);
+ }
+
+
+
+ /**
+ * Add in the components that
+ * @param target
+ */
+ protected void onUpdate (AjaxRequestTarget target) {
+ if (target != null && onUpdateComponent != null) {
+
+ target.addComponent(onUpdateComponent);
+ }
+
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see org.wicketstuff.datatable_autocomplete.form.action.IFormSubmitAction#onError(org.apache.wicket.ajax.AjaxRequestTarget, org.apache.wicket.markup.html.form.Form)
+ */
+ public final void onError(AjaxRequestTarget target, Form<T> form) {
+ onUpdate(target);
+ processError(target, form);
+ }
+
+
+ /**
+ * Implement this method to control what happens during the error case.
+ *
+ * @param target
+ * @param form
+ */
+ protected void processError(AjaxRequestTarget target, Form<T> form) {}
+
+
+ /* (non-Javadoc)
+ * @see org.wicketstuff.datatable_autocomplete.form.action.IFormSubmitAction#onSubmit(org.apache.wicket.ajax.AjaxRequestTarget, org.apache.wicket.markup.html.form.Form)
+ */
+ public final void onSubmit(AjaxRequestTarget target, Form<T> form) {
+ onUpdate(target);
+ processSubmit(target, form);
+
+ }
+
+
+ /**
+ * Implement this method to control what happens during the form submission.
+ *
+ * @param target
+ * @param form
+ */
+ protected void processSubmit(AjaxRequestTarget target, Form<T> form) {};
+
+
+
+
+}
View
17 ...autocomplete/form/action/IFormOnSubmitAction.java → ...e_autocomplete/form/action/IFormSubmitAction.java
@@ -27,9 +27,24 @@
* A way to implement the submission logic outside of the submitting component.
*
*/
-public interface IFormOnSubmitAction<T> extends IClusterable {
+public interface IFormSubmitAction<T> extends IClusterable {
+ /**
+ * Logic called when the form successfully submits.
+ *
+ * @param target
+ * @param form
+ *
+ */
public void onSubmit (AjaxRequestTarget target, Form<T> form);
+ /**
+ * Logic called when the form fails to submit due to errors.
+ *
+ * @param target
+ * @param form
+ */
+ public void onError (AjaxRequestTarget target, Form<T> form);
+
}
View
10 ...java/org/wicketstuff/datatable_autocomplete/table/DefaultSelectableTableViewPanelButtonProviderImpl.java
@@ -17,7 +17,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.wicketstuff.datatable_autocomplete.form.action.IFormOnSubmitAction;
+import org.wicketstuff.datatable_autocomplete.form.action.IFormSubmitAction;
/**
@@ -34,7 +34,7 @@
private static final Logger log = LoggerFactory
.getLogger(DefaultSelectableTableViewPanelButtonProviderImpl.class);
private String buttonLabelText;
- private IFormOnSubmitAction<?> action = null;
+ private IFormSubmitAction<?> action = null;
private final boolean clearSelectedRowOnAction;
private final boolean requireSelectedRow;
private String cssClassName;
@@ -42,7 +42,7 @@
/**
*
*/
- public DefaultSelectableTableViewPanelButtonProviderImpl(String buttonLabelText, IFormOnSubmitAction<?> action, boolean clearSelectedRowOnAction, boolean requireSelectedRow) {
+ public DefaultSelectableTableViewPanelButtonProviderImpl(String buttonLabelText, IFormSubmitAction<?> action, boolean clearSelectedRowOnAction, boolean requireSelectedRow) {
this.buttonLabelText = buttonLabelText;
this.action = action;
this.clearSelectedRowOnAction = clearSelectedRowOnAction;
@@ -71,12 +71,12 @@ public void setButtonLabelText(String buttonLabelText) {
/**
* @param action the action to set
*/
- public void setAction(IFormOnSubmitAction<?> action) {
+ public void setAction(IFormSubmitAction<?> action) {
this.action = action;
}
- public IFormOnSubmitAction<?> getButtonAction() {
+ public IFormSubmitAction<?> getButtonAction() {
return action;
}
View
4 .../src/main/java/org/wicketstuff/datatable_autocomplete/table/ISelectableTableViewPanelButtonProvider.java
@@ -16,7 +16,7 @@
package org.wicketstuff.datatable_autocomplete.table;
import org.apache.wicket.IClusterable;
-import org.wicketstuff.datatable_autocomplete.form.action.IFormOnSubmitAction;
+import org.wicketstuff.datatable_autocomplete.form.action.IFormSubmitAction;
/**
@@ -35,7 +35,7 @@
*
* @return the action to perform when this button is clicked.
*/
- public IFormOnSubmitAction<?> getButtonAction();
+ public IFormSubmitAction<?> getButtonAction();
/**
*
View
8 ...le-autocomplete/src/main/java/org/wicketstuff/datatable_autocomplete/table/SelectableTableViewPanel.java
@@ -22,7 +22,7 @@
import org.apache.wicket.extensions.markup.html.repeater.data.table.ISortableDataProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.wicketstuff.datatable_autocomplete.form.action.IFormOnSubmitAction;
+import org.wicketstuff.datatable_autocomplete.form.action.IFormSubmitAction;
import org.wicketstuff.datatable_autocomplete.selection.ITableRowSelectionHandler;
/**
@@ -217,7 +217,7 @@ public SelectableTableViewPanel(String id, String displayEntityName,
* @param formOnSubmitAction
*/
public void setEditOnSubmitAction(
- final IFormOnSubmitAction<T> formOnSubmitAction) {
+ final IFormSubmitAction<T> formOnSubmitAction) {
editButtonProvider.setAction(formOnSubmitAction);
@@ -234,7 +234,7 @@ public void setButtonCSSClass (String cssClass) {
* @param formOnSubmitAction
*/
public void setDeleteOnSubmitAction(
- final IFormOnSubmitAction<T> formOnSubmitAction) {
+ final IFormSubmitAction<T> formOnSubmitAction) {
deleteButtonProvider.setAction(formOnSubmitAction);
@@ -245,7 +245,7 @@ public void setDeleteOnSubmitAction(
/**
* @param formOnSubmitAction
*/
- public void setCreateOnSubmitAction(IFormOnSubmitAction<T> formOnSubmitAction) {
+ public void setCreateOnSubmitAction(IFormSubmitAction<T> formOnSubmitAction) {
createButtonProvider.setAction(formOnSubmitAction);
}
View
18 ...table-autocomplete/src/main/java/org/wicketstuff/datatable_autocomplete/table/button/ButtonListView.java
@@ -32,7 +32,7 @@
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import org.wicketstuff.datatable_autocomplete.button.DTAAjaxFallbackButton;
-import org.wicketstuff.datatable_autocomplete.form.action.IFormOnSubmitAction;
+import org.wicketstuff.datatable_autocomplete.form.action.IFormSubmitAction;
import org.wicketstuff.datatable_autocomplete.model.MarkupIDInStringModel;
import org.wicketstuff.datatable_autocomplete.table.ISelectableTableViewPanelButtonProvider;
@@ -84,7 +84,7 @@ protected void populateItem(ListItem<ISelectableTableViewPanelButtonProvider> it
final ISelectableTableViewPanelButtonProvider buttonProvider = item.getModelObject();
- IFormOnSubmitAction buttonAction = buttonProvider
+ IFormSubmitAction buttonAction = buttonProvider
.getButtonAction();
if (buttonAction == null) {
@@ -100,7 +100,7 @@ protected void populateItem(ListItem<ISelectableTableViewPanelButtonProvider> it
}
// if the tow is required then
- buttonAction = new IFormOnSubmitAction() {
+ buttonAction = new IFormSubmitAction() {
/**
*
@@ -137,6 +137,18 @@ public void onSubmit(AjaxRequestTarget target, Form form) {
}
+
+ /* (non-Javadoc)
+ * @see org.wicketstuff.datatable_autocomplete.form.action.IFormSubmitAction#onError(org.apache.wicket.ajax.AjaxRequestTarget, org.apache.wicket.markup.html.form.Form)
+ */
+ public void onError(AjaxRequestTarget target, Form form) {
+
+ buttonProvider.getButtonAction().onError(target, form);
+
+ }
+
+
+
};
DTAAjaxFallbackButton button;
Please sign in to comment.
Something went wrong with that request. Please try again.