/*
 * @author <a href="mailto:novotny@aei.mpg.de">Jason Novotny</a>
 * @version $Id$
 */

package org.gridlab.gridsphere.provider.portletui.beans;

import org.gridlab.gridsphere.portlet.PortletRequest;

/**
 * An <code>ActionSubmitBean</code> is a visual bean that represents an HTML button and
 * has an associated <code>DefaultPortletAction</code>
 */
public class ActionSubmitBean extends ActionBean implements TagBean {

    public static final String SUBMIT_STYLE = "portlet-form-button";
    public static final String NAME = "as";

    /**
     * Constructs a default action submit bean
     */
    public ActionSubmitBean() {
        super(NAME);
        this.cssStyle = SUBMIT_STYLE;
    }

    /**
     * Constructs an action submit bean from a supplied portlet request and bean identifier
     *
     * @param req the portlet request
     * @param beanId the bean identifier
     */
    public ActionSubmitBean(PortletRequest req, String beanId) {
        super(NAME);
        this.cssStyle = SUBMIT_STYLE;
        this.request = req;
        this.beanId = beanId;
    }

    public String toStartString() {
        return "<input class=\"" + cssStyle + "\" type=\"submit\" ";
    }

    public String toEndString() {
        String pname = (name == null) ? "" : name;
        String sname = pname;
        if (!beanId.equals("")) {
            sname = "ui_" + vbName + "_" + beanId + "_" + pname;
        } else {
            sname = action;
        }
        return "name=\"" + sname + "\" value=\"" + value + "\"/>";
    }

}

@@ -530,16 +530,53 @@
  = %22as%22;
+%0A    public boolean hideifjs = false;
 %0A%0A    /*
@@ -1121,40 +1121,616 @@
     
-public String toStartString() %7B%0A
+/**%0A     * Hides the element if the browser supports Javascript.%0A     *%0A     * @return  true/false if the element will be rendered if browser supports javascrit%0A     */%0A    public boolean isHideIfJS() %7B%0A        return hideifjs;%0A    %7D%0A%0A    /**%0A     * Determines if the bean should be rendered depending if the viewing browser supports Javascript.%0A     *%0A     * @param hideifjs  true/false to hide element if needed%0A     */%0A    public void setHideIfJS(boolean hideifjs) %7B%0A        this.hideifjs = hideifjs;%0A    %7D%0A%0A    public String toStartString() %7B%0A        if ( (supportsJS && !hideifjs) %7C%7C !supportsJS) %7B%0A    
     
@@ -1794,16 +1794,45 @@
 it%5C%22 %22;%0A
+        %7D%0A        return %22%22;%0A
     %7D%0A%0A 
@@ -1856,32 +1856,93 @@
 toEndString() %7B%0A
+        if ( (supportsJS && !hideifjs) %7C%7C !supportsJS) %7B%0A    
         String p
@@ -1980,24 +1980,28 @@
 me;%0A        
+ 
+   
 String sname
@@ -2002,32 +2002,36 @@
  sname = pname;%0A
+    
         if (!bea
@@ -2044,24 +2044,28 @@
 uals(%22%22)) %7B%0A
+    
             
@@ -2125,16 +2125,20 @@
         
+    
 %7D else %7B
@@ -2138,16 +2138,20 @@
  else %7B%0A
+    
         
@@ -2170,16 +2170,20 @@
 action;%0A
+    
         
@@ -2184,32 +2184,36 @@
       %7D%0A        
+    
 return %22name=%5C%22%22
@@ -2255,16 +2255,45 @@
 %22%5C%22/%3E%22;%0A
+        %7D%0A        return %22%22;%0A
     %7D%0A%0A%7D

support for hiding buttons when browser supports javascript