001    // Copyright 2004, 2005 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry.form;
016    
017    import org.apache.tapestry.IMarkupWriter;
018    import org.apache.tapestry.IRequestCycle;
019    
020    /**
021     * Implements a component that manages an HTML &lt;input type=submit&gt; form element. [ <a
022     * href="../../../../../ComponentReference/Submit.html">Component Reference </a>]
023     * <p>
024     * This component is generally only used when the form has multiple submit buttons, and it is
025     * important for the application to know which one was pressed. You may also want to use
026     * {@link ImageSubmit}which accomplishes much the same thing, but uses a graphic image instead.
027     * 
028     * @author Howard Lewis Ship
029     */
030    
031    public abstract class Submit extends AbstractSubmit
032    {
033        protected boolean isClicked(IRequestCycle cycle, String name)
034        {
035            // How to know which Submit button was actually
036            // clicked? When submitted, it produces a request parameter
037            // with its name and value (the value serves double duty as both
038            // the label on the button, and the parameter value).
039    
040            // If the value isn't there, then this button wasn't
041            // selected.
042            
043            return cycle.getParameter(name) != null;
044        }
045    
046        /**
047         * @see org.apache.tapestry.form.AbstractFormComponent#renderFormComponent(org.apache.tapestry.IMarkupWriter,
048         *      org.apache.tapestry.IRequestCycle)
049         */
050        protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
051        {
052            writer.beginEmpty("input");
053            writer.attribute("type", "submit");
054            writer.attribute("name", getName());
055    
056            if (isDisabled())
057                writer.attribute("disabled", "disabled");
058    
059            String label = getLabel();
060    
061            if (label != null)
062                writer.attribute("value", label);
063    
064            renderIdAttribute(writer, cycle);
065    
066            renderInformalParameters(writer, cycle);
067            
068            renderSubmitBindings(writer, cycle);
069            
070            writer.closeTag();
071        }
072    
073        /** parameter. */
074        public abstract String getLabel();
075    
076    }