1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
package org.apache.tapestry.form; |
16 |
|
|
17 |
|
import org.apache.hivemind.ApplicationRuntimeException; |
18 |
|
import org.apache.hivemind.util.Defense; |
19 |
|
import org.apache.tapestry.IComponent; |
20 |
|
import org.apache.tapestry.IForm; |
21 |
|
import org.apache.tapestry.IMarkupWriter; |
22 |
|
import org.apache.tapestry.IRequestCycle; |
23 |
|
import org.apache.tapestry.engine.DirectServiceParameter; |
24 |
|
import org.apache.tapestry.json.JSONLiteral; |
25 |
|
import org.apache.tapestry.json.JSONObject; |
26 |
|
|
27 |
|
import java.util.List; |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
9 |
public abstract class LinkSubmit extends AbstractSubmit |
37 |
|
{ |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
public static final String ATTRIBUTE_NAME = "org.apache.tapestry.form.LinkSubmit"; |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
protected boolean isClicked(IRequestCycle cycle, String name) |
51 |
|
{ |
52 |
3 |
String value = cycle.getParameter(FormConstants.SUBMIT_NAME_PARAMETER); |
53 |
|
|
54 |
3 |
return name.equals(value); |
55 |
|
} |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle) |
62 |
|
{ |
63 |
3 |
boolean disabled = isDisabled(); |
64 |
|
|
65 |
3 |
IForm form = getForm(); |
66 |
3 |
String type = getSubmitType(); |
67 |
|
|
68 |
3 |
Defense.notNull(type, "submitType"); |
69 |
|
|
70 |
3 |
List update = getUpdateComponents(); |
71 |
3 |
boolean isAsync = isAsync() || update != null && update.size() > 0; |
72 |
|
|
73 |
3 |
if (!disabled) |
74 |
|
{ |
75 |
2 |
writer.begin("a"); |
76 |
|
|
77 |
2 |
String js = "tapestry.form." + type + "('" + form.getClientId() + "', '" + getName() + "'"; |
78 |
|
|
79 |
2 |
if (isAsync) |
80 |
|
{ |
81 |
1 |
JSONObject json = new JSONObject(); |
82 |
1 |
json.put(new JSONLiteral("async"), Boolean.TRUE); |
83 |
1 |
json.put(new JSONLiteral("json"), isJson()); |
84 |
|
|
85 |
1 |
DirectServiceParameter dsp = new DirectServiceParameter(form, null, this); |
86 |
1 |
json.put(new JSONLiteral("url"), new JSONLiteral("this.href")); |
87 |
|
|
88 |
1 |
writer.attribute("href", getDirectService().getLink(true, dsp).getURL()); |
89 |
1 |
writer.attribute("onClick", js + "," + json.toString() + "); return false;"); |
90 |
1 |
} else { |
91 |
|
|
92 |
1 |
writer.attribute("href", "javascript:" + js + ");"); |
93 |
|
} |
94 |
|
|
95 |
2 |
renderIdAttribute(writer, cycle); |
96 |
2 |
renderInformalParameters(writer, cycle); |
97 |
|
} |
98 |
|
|
99 |
3 |
renderBody(writer, cycle); |
100 |
|
|
101 |
3 |
if (!disabled) |
102 |
2 |
writer.end(); |
103 |
3 |
} |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
protected void prepareForRender(IRequestCycle cycle) |
111 |
|
{ |
112 |
2 |
IComponent outer = (IComponent) cycle.getAttribute(ATTRIBUTE_NAME); |
113 |
|
|
114 |
2 |
if (outer != null) |
115 |
1 |
throw new ApplicationRuntimeException(FormMessages.linkSubmitMayNotNest(this, outer), |
116 |
|
this, getLocation(), null); |
117 |
|
|
118 |
1 |
cycle.setAttribute(ATTRIBUTE_NAME, this); |
119 |
1 |
} |
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
protected void cleanupAfterRender(IRequestCycle cycle) |
125 |
|
{ |
126 |
1 |
cycle.removeAttribute(ATTRIBUTE_NAME); |
127 |
1 |
} |
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
protected boolean getCanTakeFocus() |
133 |
|
{ |
134 |
0 |
return false; |
135 |
|
} |
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
protected boolean getRenderBodyOnRewind() |
142 |
|
{ |
143 |
1 |
return true; |
144 |
|
} |
145 |
|
} |