Save This Page
Home » struts-2.1.8.1-src » org.apache » struts2 » components » [javadoc | source]
    1   /*
    2    * $Id: Submit.java 678079 2008-07-19 00:08:47Z musachy $
    3    *
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
   10    * with the License.  You may obtain a copy of the License at
   11    *
   12    *  http://www.apache.org/licenses/LICENSE-2.0
   13    *
   14    * Unless required by applicable law or agreed to in writing,
   15    * software distributed under the License is distributed on an
   16    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   17    * KIND, either express or implied.  See the License for the
   18    * specific language governing permissions and limitations
   19    * under the License.
   20    */
   21   
   22   package org.apache.struts2.components;
   23   
   24   import java.io.Writer;
   25   
   26   import javax.servlet.http.HttpServletRequest;
   27   import javax.servlet.http.HttpServletResponse;
   28   
   29   import org.apache.struts2.views.annotations.StrutsTag;
   30   import org.apache.struts2.views.annotations.StrutsTagAttribute;
   31   
   32   import com.opensymphony.xwork2.util.ValueStack;
   33   import com.opensymphony.xwork2.util.logging.Logger;
   34   import com.opensymphony.xwork2.util.logging.LoggerFactory;
   35   
   36   /**
   37    * <!-- START SNIPPET: javadoc -->
   38    * Render a submit button. The submit tag is used together with the form tag to provide asynchronous form submissions.
   39    * The submit can have three different types of rendering:
   40    * <ul>
   41    * <li>input: renders as html &lt;input type="submit"...&gt;</li>
   42    * <li>image: renders as html &lt;input type="image"...&gt;</li>
   43    * <li>button: renders as html &lt;button type="submit"...&gt;</li>
   44    * </ul>
   45    * Please note that the button type has advantages by adding the possibility to seperate the submitted value from the
   46    * text shown on the button face, but has issues with Microsoft Internet Explorer at least up to 6.0
   47    * <!-- END SNIPPET: javadoc -->
   48    */
   49   @StrutsTag(
   50       name="submit",
   51       tldTagClass="org.apache.struts2.views.jsp.ui.SubmitTag",
   52       description="Render a submit button",
   53       allowDynamicAttributes=true)
   54   public class Submit extends FormButton {
   55   
   56       private static final Logger LOG = LoggerFactory.getLogger(Submit.class);
   57       final public static String OPEN_TEMPLATE = "submit";
   58       final public static String TEMPLATE = "submit-close";
   59       protected String src;
   60   
   61       public Submit(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
   62           super(stack, request, response);
   63       }
   64   
   65       public String getDefaultOpenTemplate() {
   66           return OPEN_TEMPLATE;
   67       }
   68   
   69       protected String getDefaultTemplate() {
   70           return TEMPLATE;
   71       }
   72   
   73       public void evaluateParams() {
   74           if ((key == null) && (value == null)) {
   75               value = "Submit";
   76           }
   77   
   78           if (((key != null)) && (value == null)) {
   79               this.value = "%{getText('"+key +"')}";
   80           }
   81   
   82           super.evaluateParams();
   83       }
   84   
   85       public void evaluateExtraParams() {
   86           super.evaluateExtraParams();
   87   
   88           if (src != null)
   89               addParameter("src", findString(src));
   90       }
   91   
   92       /**
   93        * Indicate whether the concrete button supports the type "image".
   94        *
   95        * @return <tt>true</tt> to indicate type image is supported.
   96        */
   97       protected boolean supportsImageType() {
   98           return true;
   99       }
  100   
  101       @StrutsTagAttribute(description="Supply an image src for <i>image</i> type submit button. Will have no effect for types <i>input</i> and <i>button</i>.")
  102       public void setSrc(String src) {
  103           this.src = src;
  104       }
  105   
  106   
  107       @Override
  108       public boolean usesBody() {
  109           return true;
  110       }
  111   
  112       /**
  113        * Overrides to be able to render body in a template rather than always before the template
  114        */
  115       public boolean end(Writer writer, String body) {
  116           evaluateParams();
  117           try {
  118               addParameter("body", body);
  119   
  120               mergeTemplate(writer, buildTemplateName(template, getDefaultTemplate()));
  121           } catch (Exception e) {
  122               LOG.error("error when rendering", e);
  123           }
  124           finally {
  125               popComponentStack();
  126           }
  127   
  128           return false;
  129       }
  130   }

Save This Page
Home » struts-2.1.8.1-src » org.apache » struts2 » components » [javadoc | source]