|
|||||||||||||||||||
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 | |||||||||||||||
AbstractSubmit.java | 100% | 100% | 100% | 100% |
|
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 java.util.Collection;
|
|
18 |
|
|
19 |
import org.apache.tapestry.IActionListener;
|
|
20 |
import org.apache.tapestry.IForm;
|
|
21 |
import org.apache.tapestry.IMarkupWriter;
|
|
22 |
import org.apache.tapestry.IRequestCycle;
|
|
23 |
import org.apache.tapestry.listener.ListenerInvoker;
|
|
24 |
|
|
25 |
/**
|
|
26 |
* Superclass for components submitting their form.
|
|
27 |
*
|
|
28 |
* @author Richard Lewis-Shell
|
|
29 |
* @since 4.0
|
|
30 |
*/
|
|
31 |
|
|
32 |
abstract class AbstractSubmit extends AbstractFormComponent |
|
33 |
{ |
|
34 |
|
|
35 |
/**
|
|
36 |
* Determine if this submit component was clicked.
|
|
37 |
*
|
|
38 |
* @param cycle
|
|
39 |
* @param name
|
|
40 |
* @return true if this submit was clicked
|
|
41 |
*/
|
|
42 |
protected abstract boolean isClicked(IRequestCycle cycle, String name); |
|
43 |
|
|
44 |
/**
|
|
45 |
* Write the tag (and any nested content) for this submit component.
|
|
46 |
*
|
|
47 |
* @param writer
|
|
48 |
* @param cycle
|
|
49 |
* @param name
|
|
50 |
*/
|
|
51 |
protected abstract void writeTag(IMarkupWriter writer, IRequestCycle cycle, String name); |
|
52 |
|
|
53 | 7 |
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) |
54 |
{ |
|
55 | 7 |
IForm form = getForm(cycle); |
56 |
|
|
57 | 7 |
if (form.wasPrerendered(writer, this)) |
58 | 1 |
return;
|
59 |
|
|
60 | 6 |
boolean rewinding = form.isRewinding();
|
61 |
|
|
62 | 6 |
String name = form.getElementId(this);
|
63 |
|
|
64 | 6 |
setName(name); |
65 |
|
|
66 | 6 |
if (rewinding)
|
67 |
{ |
|
68 |
// Don't bother doing anything if disabled.
|
|
69 | 3 |
if (isDisabled())
|
70 | 1 |
return;
|
71 |
|
|
72 | 2 |
if (isClicked(cycle, name))
|
73 | 1 |
handleClick(cycle, form); |
74 |
|
|
75 | 2 |
return;
|
76 |
} |
|
77 |
|
|
78 | 3 |
writeTag(writer, cycle, name); |
79 |
} |
|
80 |
|
|
81 | 7 |
void handleClick(final IRequestCycle cycle, IForm form)
|
82 |
{ |
|
83 | 7 |
if (isParameterBound("selected")) |
84 | 3 |
setSelected(getTag()); |
85 |
|
|
86 | 7 |
final IActionListener listener = getListener(); |
87 |
|
|
88 | 7 |
if (listener == null) |
89 | 3 |
return;
|
90 |
|
|
91 | 4 |
final ListenerInvoker listenerInvoker = getListenerInvoker(); |
92 |
|
|
93 | 4 |
Object parameters = getParameters(); |
94 | 4 |
if (parameters != null) |
95 |
{ |
|
96 | 2 |
if (parameters instanceof Collection) |
97 |
{ |
|
98 | 1 |
cycle.setListenerParameters(((Collection) parameters).toArray()); |
99 |
} |
|
100 |
else
|
|
101 |
{ |
|
102 | 1 |
cycle.setListenerParameters(new Object[]
|
103 |
{ parameters }); |
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 |
// Have a listener; notify it now, or defer for later?
|
|
108 |
|
|
109 | 4 |
Runnable notify = new Runnable()
|
110 |
{ |
|
111 | 4 |
public void run() |
112 |
{ |
|
113 | 4 |
listenerInvoker.invokeListener(listener, AbstractSubmit.this, cycle);
|
114 |
} |
|
115 |
}; |
|
116 |
|
|
117 | 4 |
if (getDefer())
|
118 | 3 |
form.addDeferredRunnable(notify); |
119 |
else
|
|
120 | 1 |
notify.run(); |
121 |
} |
|
122 |
|
|
123 |
/** parameter */
|
|
124 |
public abstract boolean isDisabled(); |
|
125 |
|
|
126 |
/** parameter */
|
|
127 |
public abstract IActionListener getListener();
|
|
128 |
|
|
129 |
/** parameter */
|
|
130 |
public abstract Object getTag();
|
|
131 |
|
|
132 |
/** parameter */
|
|
133 |
public abstract void setSelected(Object tag); |
|
134 |
|
|
135 |
/** parameter */
|
|
136 |
public abstract boolean getDefer(); |
|
137 |
|
|
138 |
/** parameter */
|
|
139 |
public abstract Object getParameters();
|
|
140 |
|
|
141 |
/** Injected */
|
|
142 |
public abstract ListenerInvoker getListenerInvoker();
|
|
143 |
} |
|
144 |
|
|