|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
Submit.java | 0% | 0% | 0% | 0% |
|
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.IActionListener;
|
|
18 |
import org.apache.tapestry.IBinding;
|
|
19 |
import org.apache.tapestry.IForm;
|
|
20 |
import org.apache.tapestry.IMarkupWriter;
|
|
21 |
import org.apache.tapestry.IRequestCycle;
|
|
22 |
|
|
23 |
/**
|
|
24 |
* Implements a component that manages an HTML <input type=submit> form element. [ <a
|
|
25 |
* href="../../../../../ComponentReference/Submit.html">Component Reference </a>]
|
|
26 |
* <p>
|
|
27 |
* This component is generally only used when the form has multiple submit buttons, and it is
|
|
28 |
* important for the application to know which one was pressed. You may also want to use
|
|
29 |
* {@link ImageSubmit}which accomplishes much the same thing, but uses a graphic image instead.
|
|
30 |
*
|
|
31 |
* @author Howard Lewis Ship
|
|
32 |
*/
|
|
33 |
|
|
34 |
public abstract class Submit extends AbstractFormComponent |
|
35 |
{ |
|
36 |
|
|
37 | 0 |
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) |
38 |
{ |
|
39 |
|
|
40 | 0 |
IForm form = getForm(cycle); |
41 |
|
|
42 | 0 |
if (form.wasPrerendered(writer, this)) |
43 | 0 |
return;
|
44 |
|
|
45 | 0 |
boolean rewinding = form.isRewinding();
|
46 |
|
|
47 | 0 |
String name = form.getElementId(this);
|
48 |
|
|
49 | 0 |
if (rewinding)
|
50 |
{ |
|
51 |
// Don't bother doing anything if disabled.
|
|
52 |
|
|
53 | 0 |
if (isDisabled())
|
54 | 0 |
return;
|
55 |
|
|
56 |
// How to know which Submit button was actually
|
|
57 |
// clicked? When submitted, it produces a request parameter
|
|
58 |
// with its name and value (the value serves double duty as both
|
|
59 |
// the label on the button, and the parameter value).
|
|
60 |
|
|
61 | 0 |
String value = cycle.getParameter(name); |
62 |
|
|
63 |
// If the value isn't there, then this button wasn't
|
|
64 |
// selected.
|
|
65 |
|
|
66 | 0 |
if (value == null) |
67 | 0 |
return;
|
68 |
|
|
69 | 0 |
IBinding selectedBinding = getBinding("selected");
|
70 |
|
|
71 | 0 |
if (selectedBinding != null) |
72 | 0 |
selectedBinding.setObject(getTag()); |
73 |
|
|
74 | 0 |
IActionListener listener = getListener(); |
75 |
|
|
76 | 0 |
if (listener != null) |
77 | 0 |
listener.actionTriggered(this, cycle);
|
78 |
|
|
79 | 0 |
return;
|
80 |
} |
|
81 |
|
|
82 | 0 |
writer.beginEmpty("input");
|
83 | 0 |
writer.attribute("type", "submit"); |
84 | 0 |
writer.attribute("name", name);
|
85 |
|
|
86 | 0 |
if (isDisabled())
|
87 | 0 |
writer.attribute("disabled", "disabled"); |
88 |
|
|
89 | 0 |
String label = getLabel(); |
90 |
|
|
91 | 0 |
if (label != null) |
92 | 0 |
writer.attribute("value", label);
|
93 |
|
|
94 | 0 |
renderInformalParameters(writer, cycle); |
95 |
|
|
96 | 0 |
writer.closeTag(); |
97 |
} |
|
98 |
|
|
99 |
public abstract String getLabel();
|
|
100 |
|
|
101 |
public abstract boolean isDisabled(); |
|
102 |
|
|
103 |
public abstract IActionListener getListener();
|
|
104 |
|
|
105 |
public abstract Object getTag();
|
|
106 |
|
|
107 |
} |
|