Commits

rgielen  committed 0df4f3f

Issue number: WW-1256
Obtained from:
Submitted by:
Reviewed by:
Refactored submit and reset to share a single superclass

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@2504573baa09-0c28-0410-bef9-dab3c582ae83

  • Participants
  • Parent commits f5f398f

Comments (0)

Files changed (3)

File src/java/com/opensymphony/webwork/components/FormButton.java

+/*
+ * The IT-neering.net Commercial Software License, Version 1.0
+ *
+ * Copyright (c) 2005 Rene Gielen. All rights reserved.
+ *
+ * IT-NEERING.NET PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ *
+ * For more information on IT-neering.net, please see <http://it-neering.net/>.
+ */
+package com.opensymphony.webwork.components;
+
+import com.opensymphony.xwork.util.OgnlValueStack;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * FormButton.
+ *
+ * @author <a href="mailto:gielen@it-neering.net">Rene Gielen</a>
+ */
+
+public abstract class FormButton extends UIBean {
+
+    static final String BUTTONTYPE_INPUT = "input";
+    static final String BUTTONTYPE_BUTTON = "button";
+    static final String BUTTONTYPE_IMAGE = "image";
+
+    protected String action;
+    protected String method;
+    protected String align;
+    protected String type;
+
+    public FormButton(OgnlValueStack stack, HttpServletRequest request, HttpServletResponse response) {
+        super(stack, request, response);
+    }
+
+    public void evaluateParams() {
+        if (align == null) {
+            align = "right";
+        }
+
+        String submitType = BUTTONTYPE_INPUT;
+        if (type != null && (BUTTONTYPE_BUTTON.equalsIgnoreCase(type) || (supportsImageType() && BUTTONTYPE_IMAGE.equalsIgnoreCase(type))))
+        {
+            submitType = type;
+        }
+
+        super.evaluateParams();
+
+        addParameter("type", submitType);
+
+        if (!BUTTONTYPE_INPUT.equals(submitType) && (label == null)) {
+            addParameter("label", getParameters().get("nameValue"));
+        }
+
+        if (action != null || method != null) {
+            String name;
+
+            if (action != null) {
+                name = "action:" + findString(action);
+
+                if (method != null) {
+                    name += "!" + findString(method);
+                }
+            } else {
+                name = "method:" + findString(method);
+            }
+
+            addParameter("name", name);
+        }
+
+        addParameter("align", findString(align));
+
+    }
+
+    /**
+     * Indicate whether the concrete button supports the type "image".
+     *
+     * @return <tt>true</tt> if type image is supported.
+     */
+    protected abstract boolean supportsImageType();
+
+    /**
+     * Set action attribute.
+     *
+     * @ww.tagattribute required="false" type="String"
+     */
+    public void setAction(String action) {
+        this.action = action;
+    }
+
+    /**
+     * Set method attribute.
+     *
+     * @ww.tagattribute required="false" type="String"
+     */
+    public void setMethod(String method) {
+        this.method = method;
+    }
+
+    /**
+     * HTML align attribute.
+     *
+     * @ww.tagattribute required="false" type="String"
+     */
+    public void setAlign(String align) {
+        this.align = align;
+    }
+
+    /**
+     * The type of submit to use. Valid values are <i>input</i>, <i>button</i> and <i>image</i>.
+     *
+     * @ww.tagattribute required="false" type="String" default="input"
+     */
+    public void setType(String type) {
+        this.type = type;
+    }
+}

File src/java/com/opensymphony/webwork/components/Reset.java

  * @ww.tag name="reset" tld-body-content="JSP" tld-tag-class="com.opensymphony.webwork.views.jsp.ui.ResetTag"
  * description="Render a reset button"
  */
-public class Reset extends UIBean {
+public class Reset extends FormButton {
     final public static String TEMPLATE = "reset";
 
-    static final String RESETTYPE_INPUT = "input";
-    static final String RESETTYPE_BUTTON = "button";
-
     protected String action;
     protected String method;
     protected String align;
     }
 
     public void evaluateParams() {
-        if (align == null) {
-            align = "right";
-        }
-
-        String resetType = Reset.RESETTYPE_INPUT;
-        if (type != null && (Reset.RESETTYPE_BUTTON.equalsIgnoreCase(type)) ) {
-            resetType = type;
-        }
-        addParameter("type", resetType);
 
         if (value == null) {
             value = "Reset";
         }
 
         super.evaluateParams();
-
-        if (!Reset.RESETTYPE_INPUT.equals(resetType) && (label == null)) {
-            addParameter("label", getParameters().get("nameValue"));
-        }
-
-        if (action != null || method != null) {
-            String name;
-
-            if (action != null) {
-                name = "action:" + findString(action);
-
-                if (method != null) {
-                    name += "!" + findString(method);
-                }
-            } else {
-                name = "method:" + findString(method);
-            }
-
-            addParameter("name", name);
-        }
-
-        addParameter("align", findString(align));
-
-    }
-
-    /**
-     * Set action attribute.
-     * @ww.tagattribute required="false" type="String"
-     */
-    public void setAction(String action) {
-        this.action = action;
-    }
-
-    /**
-     * Set method attribute.
-     * @ww.tagattribute required="false" type="String"
-     */
-    public void setMethod(String method) {
-        this.method = method;
-    }
-
-    /**
-     * HTML align attribute.
-     * @ww.tagattribute required="false" type="String"
-     */
-    public void setAlign(String align) {
-        this.align = align;
     }
 
     /**
-     * The type of reset to use. Valid values are <i>input</i> and <i>button</i>.
-     * @ww.tagattribute required="false" type="String" default="input"
+     * Indicate whether the concrete button supports the type "image".
+     *
+     * @return <tt>false</tt> to indicate type image is supported.
      */
-    public void setType(String type) {
-        this.type = type;
+    protected boolean supportsImageType() {
+        return false;
     }
 
     /**
-     * Supply a reset button text apart from reset value. Will have no effect for <i>input</i> type reset, since button text will always be the value parameter.
+     * Supply a reset button text apart from reset value. Will have no effect for <i>input</i> type reset, since button
+     * text will always be the value parameter.
+     *
      * @ww.tagattribute required="false"
      */
     public void setLabel(String label) {

File src/java/com/opensymphony/webwork/components/Submit.java

  * @ww.tag name="submit" tld-body-content="JSP" tld-tag-class="com.opensymphony.webwork.views.jsp.ui.SubmitTag"
  * description="Render a submit button"
  */
-public class Submit extends UIBean {
+public class Submit extends FormButton {
     final public static String TEMPLATE = "submit";
 
-    static final String SUBMITTYPE_INPUT = "input";
-    static final String SUBMITTYPE_BUTTON = "button";
-    static final String SUBMITTYPE_IMAGE = "image";
-
-    protected String action;
-    protected String method;
-    protected String align;
     protected String resultDivId;
     protected String onLoadJS;
     protected String notifyTopics;
     protected String listenTopics;
     protected String preInvokeJS;
-    protected String type;
     protected String src;
 
     public Submit(OgnlValueStack stack, HttpServletRequest request, HttpServletResponse response) {
     }
 
     public void evaluateParams() {
-        if (align == null) {
-            align = "right";
-        }
-
-        String submitType = SUBMITTYPE_INPUT;
-        if (type != null && (SUBMITTYPE_BUTTON.equalsIgnoreCase(type) || SUBMITTYPE_IMAGE.equalsIgnoreCase(type)) ) {
-        	submitType = type;
-        }
-        addParameter("type", submitType);
 
         if (value == null) {
             value = "Submit";
 
         super.evaluateParams();
 
-        if (!SUBMITTYPE_INPUT.equals(submitType) && (label == null)) {
-            addParameter("label", getParameters().get("nameValue"));
-        }
-
         if (null != src) {
             addParameter("src", findString(src));
         }
 
-        if (action != null || method != null) {
-            String name;
-
-            if (action != null) {
-                name = "action:" + findString(action);
-
-                if (method != null) {
-                    name += "!" + findString(method);
-                }
-            } else {
-                name = "method:" + findString(method);
-            }
-            
-            addParameter("name", name);
-        }
-
-        addParameter("align", findString(align));
-
         if (null != resultDivId) {
             addParameter("resultDivId", findString(resultDivId));
         }
     }
 
     /**
-     * Set action attribute.
-     * @ww.tagattribute required="false" type="String"
-     */
-    public void setAction(String action) {
-        this.action = action;
-    }
-
-    /**
-     * Set method attribute.
-     * @ww.tagattribute required="false" type="String"
+     * Indicate whether the concrete button supports the type "image".
+     *
+     * @return <tt>true</tt> to indicate type image is supported.
      */
-    public void setMethod(String method) {
-        this.method = method;
-    }
-
-    /**
-     * HTML align attribute.
-     * @ww.tagattribute required="false" type="String"
-     */
-    public void setAlign(String align) {
-        this.align = align;
+    protected boolean supportsImageType() {
+        return true;
     }
 
     /**
     }
 
     /**
-     * The type of submit to use. Valid values are <i>input</i>, <i>button</i> and <i>image</i>.
-     * @ww.tagattribute required="false" type="String" default="input"
-     */
-    public void setType(String type) {
-        this.type = type;
-    }
-
-    /**
      * Supply a submit button text apart from submit value. Will have no effect for <i>input</i> type submit, since button text will always be the value parameter. For the type <i>image</i>, alt parameter will be set to this value.
      * @ww.tagattribute required="false"
      */