KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > form > Submit


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.form;
16
17 import org.apache.tapestry.IMarkupWriter;
18 import org.apache.tapestry.IRequestCycle;
19
20 /**
21  * Implements a component that manages an HTML &lt;input type=submit&gt; form element. [ <a
22  * HREF="../../../../../ComponentReference/Submit.html">Component Reference </a>]
23  * <p>
24  * This component is generally only used when the form has multiple submit buttons, and it is
25  * important for the application to know which one was pressed. You may also want to use
26  * {@link ImageSubmit}which accomplishes much the same thing, but uses a graphic image instead.
27  *
28  * @author Howard Lewis Ship
29  */

30
31 public abstract class Submit extends AbstractSubmit
32 {
33     protected boolean isClicked(IRequestCycle cycle, String JavaDoc name)
34     {
35         // How to know which Submit button was actually
36
// clicked? When submitted, it produces a request parameter
37
// with its name and value (the value serves double duty as both
38
// the label on the button, and the parameter value).
39

40         // If the value isn't there, then this button wasn't
41
// selected.
42
return cycle.getParameter(name) != null;
43     }
44
45     /**
46      * @see org.apache.tapestry.form.AbstractFormComponent#renderFormComponent(org.apache.tapestry.IMarkupWriter,
47      * org.apache.tapestry.IRequestCycle)
48      */

49     protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
50     {
51         writer.beginEmpty("input");
52         writer.attribute("type", "submit");
53         writer.attribute("name", getName());
54
55         if (isDisabled())
56             writer.attribute("disabled", "disabled");
57
58         String JavaDoc label = getLabel();
59
60         if (label != null)
61             writer.attribute("value", label);
62
63         renderIdAttribute(writer, cycle);
64
65         renderInformalParameters(writer, cycle);
66
67         writer.closeTag();
68     }
69
70     /** parameter */
71     public abstract String JavaDoc getLabel();
72
73 }
Popular Tags