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
015package org.apache.tapestry.form;
016
017import org.apache.tapestry.IMarkupWriter;
018import 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
031public 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        return cycle.getParameter(name) != null;
043    }
044
045    /**
046     * @see org.apache.tapestry.form.AbstractFormComponent#renderFormComponent(org.apache.tapestry.IMarkupWriter,
047     *      org.apache.tapestry.IRequestCycle)
048     */
049    protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
050    {
051        writer.beginEmpty("input");
052        writer.attribute("type", "submit");
053        writer.attribute("name", getName());
054
055        if (isDisabled())
056            writer.attribute("disabled", "disabled");
057
058        String label = getLabel();
059
060        if (label != null)
061            writer.attribute("value", label);
062
063        renderIdAttribute(writer, cycle);
064
065        renderInformalParameters(writer, cycle);
066
067        writer.closeTag();
068    }
069
070    /** parameter */
071    public abstract String getLabel();
072
073}