1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.form; |
16 |
| |
17 |
| import java.util.HashMap; |
18 |
| import java.util.Map; |
19 |
| |
20 |
| import org.apache.hivemind.ApplicationRuntimeException; |
21 |
| import org.apache.hivemind.HiveMind; |
22 |
| import org.apache.tapestry.IComponent; |
23 |
| import org.apache.tapestry.IForm; |
24 |
| import org.apache.tapestry.IMarkupWriter; |
25 |
| import org.apache.tapestry.IRequestCycle; |
26 |
| import org.apache.tapestry.IScript; |
27 |
| import org.apache.tapestry.PageRenderSupport; |
28 |
| import org.apache.tapestry.TapestryUtils; |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
| public abstract class LinkSubmit extends AbstractSubmit |
38 |
| { |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
| public static final String ATTRIBUTE_NAME = "org.apache.tapestry.form.LinkSubmit"; |
46 |
| |
47 |
2
| protected boolean isClicked(IRequestCycle cycle, String name)
|
48 |
| { |
49 |
2
| String value = cycle.getParameter(name);
|
50 |
| |
51 |
2
| return HiveMind.isNonBlank(value);
|
52 |
| } |
53 |
| |
54 |
| public abstract IScript getScript(); |
55 |
| |
56 |
| |
57 |
| |
58 |
| |
59 |
| |
60 |
2
| protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
|
61 |
| { |
62 |
2
| boolean disabled = isDisabled();
|
63 |
| |
64 |
2
| IForm form = getForm();
|
65 |
2
| String name = getName();
|
66 |
| |
67 |
2
| String hiddenId = cycle.getUniqueId(TapestryUtils
|
68 |
| .convertTapestryIdToNMToken(getIdParameter())); |
69 |
| |
70 |
| |
71 |
| |
72 |
2
| setClientId(hiddenId);
|
73 |
| |
74 |
| |
75 |
| |
76 |
| |
77 |
| |
78 |
2
| form.addHiddenValue(name, hiddenId, "");
|
79 |
| |
80 |
2
| if (!disabled)
|
81 |
| { |
82 |
1
| PageRenderSupport pageRenderSupport = TapestryUtils.getPageRenderSupport(cycle, this);
|
83 |
| |
84 |
1
| Map symbols = new HashMap();
|
85 |
1
| symbols.put("form", form);
|
86 |
1
| symbols.put("hiddenId", hiddenId);
|
87 |
| |
88 |
1
| getScript().execute(cycle, pageRenderSupport, symbols);
|
89 |
| |
90 |
1
| writer.begin("a");
|
91 |
1
| writer.attribute("href", (String) symbols.get("href"));
|
92 |
1
| renderInformalParameters(writer, cycle);
|
93 |
| } |
94 |
| |
95 |
2
| renderBody(writer, cycle);
|
96 |
| |
97 |
2
| if (!disabled)
|
98 |
1
| writer.end();
|
99 |
| |
100 |
| } |
101 |
| |
102 |
| |
103 |
| |
104 |
| |
105 |
2
| protected void prepareForRender(IRequestCycle cycle)
|
106 |
| { |
107 |
2
| IComponent outer = (IComponent) cycle.getAttribute(ATTRIBUTE_NAME);
|
108 |
| |
109 |
2
| if (outer != null)
|
110 |
1
| throw new ApplicationRuntimeException(FormMessages.linkSubmitMayNotNest(this, outer),
|
111 |
| this, getLocation(), null); |
112 |
| |
113 |
1
| cycle.setAttribute(ATTRIBUTE_NAME, this);
|
114 |
| } |
115 |
| |
116 |
| |
117 |
| |
118 |
| |
119 |
1
| protected void cleanupAfterRender(IRequestCycle cycle)
|
120 |
| { |
121 |
1
| cycle.removeAttribute(ATTRIBUTE_NAME);
|
122 |
| } |
123 |
| |
124 |
| |
125 |
| |
126 |
| |
127 |
0
| protected boolean getCanTakeFocus()
|
128 |
| { |
129 |
0
| return false;
|
130 |
| } |
131 |
| } |