Skip to content

Instantly share code, notes, and snippets.

@mkgl
Created April 6, 2016 07:36
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mkgl/d27d68fd0cf599af3d50508b87df6779 to your computer and use it in GitHub Desktop.
check validity *before* firing the action, otherwise session can be saved and thus validators might be affected
--- a/magnolia-ui-dialog/src/main/java/info/magnolia/ui/dialog/actionarea/renderer/DefaultEditorActionRenderer.java
+++ b/magnolia-ui-dialog/src/main/java/info/magnolia/ui/dialog/actionarea/renderer/DefaultEditorActionRenderer.java
@@ -64,12 +64,19 @@ public class DefaultEditorActionRenderer implements ActionRenderer {
ClickListener clickListener = new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
- listener.onActionFired(name, new HashMap<String, Object>());
- // make sure we don't trigger useless validation for all form fields when the action is 'cancel'.
- if (!BaseDialog.CANCEL_ACTION_NAME.equals(name) && listener instanceof EditorValidator && !((EditorValidator) listener).isValid()) {
- // have to re-enable button since validation failed
- button.setEnabled(true);
+ // don't trigger validation for all fields when the action is 'cancel'.
+ if (!BaseDialog.CANCEL_ACTION_NAME.equals(name)) {
+ // check validity *before* firing the action, otherwise session can be saved and thus validators might be affected
+ // TODO: well ideally, we shouldn't check validation at all here though (only validate once in the save action)
+ boolean isValid = !(listener instanceof EditorValidator) || ((EditorValidator) listener).isValid();
+ System.out.println("ACTION RENDERER: " + (isValid ? "VALID" : "NOT VALID"));
+ if (!isValid) {
+ // validation will fail, so re-enable that button
+ button.setEnabled(true);
+ }
}
+
+ listener.onActionFired(name, new HashMap<String, Object>());
}
};
this.button = new Button(label, clickListener);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment