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.tapestry.IForm; |
19 |
| import org.apache.tapestry.IMarkupWriter; |
20 |
| import org.apache.tapestry.IRequestCycle; |
21 |
| import org.apache.tapestry.PageRenderSupport; |
22 |
| import org.apache.tapestry.Tapestry; |
23 |
| import org.apache.tapestry.TapestryUtils; |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| public abstract class LinkSubmit extends AbstractSubmit |
33 |
| { |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| public static final String ATTRIBUTE_NAME = "org.apache.tapestry.form.LinkSubmit"; |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
| |
46 |
| |
47 |
| public static final String ATTRIBUTE_FUNCTION_NAME = "org.apache.tapestry.form.LinkSubmit_function"; |
48 |
| |
49 |
0
| protected boolean isClicked(IRequestCycle cycle, String name)
|
50 |
| { |
51 |
| |
52 |
| |
53 |
0
| String value = cycle.getParameter("_linkSubmit");
|
54 |
| |
55 |
| |
56 |
| |
57 |
0
| return value != null && value.equals(name);
|
58 |
| } |
59 |
| |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
0
| protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
|
65 |
| { |
66 |
0
| boolean disabled = isDisabled();
|
67 |
| |
68 |
0
| IMarkupWriter wrappedWriter;
|
69 |
| |
70 |
0
| if (!disabled)
|
71 |
| { |
72 |
0
| PageRenderSupport pageRenderSupport = TapestryUtils.getPageRenderSupport(cycle, this);
|
73 |
| |
74 |
| |
75 |
0
| if (cycle.getAttribute(ATTRIBUTE_FUNCTION_NAME) == null)
|
76 |
| { |
77 |
0
| pageRenderSupport
|
78 |
| .addBodyScript("function submitLink(form, elementId) { form._linkSubmit.value = elementId; if (form.onsubmit == null || form.onsubmit()) form.submit(); }"); |
79 |
0
| cycle.setAttribute(ATTRIBUTE_FUNCTION_NAME, this);
|
80 |
| } |
81 |
| |
82 |
0
| IForm form = getForm();
|
83 |
0
| String formName = form.getName();
|
84 |
| |
85 |
| |
86 |
0
| String formHiddenFieldAttributeName = ATTRIBUTE_FUNCTION_NAME + formName;
|
87 |
0
| if (cycle.getAttribute(formHiddenFieldAttributeName) == null)
|
88 |
| { |
89 |
0
| writer.beginEmpty("input");
|
90 |
0
| writer.attribute("type", "hidden");
|
91 |
0
| writer.attribute("name", "_linkSubmit");
|
92 |
0
| cycle.setAttribute(formHiddenFieldAttributeName, this);
|
93 |
| } |
94 |
| |
95 |
0
| writer.begin("a");
|
96 |
0
| renderIdAttribute(writer, cycle);
|
97 |
0
| writer.attribute("href", "javascript:submitLink(Tapestry.find('" + formName + "', '"
|
98 |
| + getName() + "');"); |
99 |
| |
100 |
| |
101 |
| |
102 |
| |
103 |
0
| wrappedWriter = writer.getNestedWriter();
|
104 |
| } |
105 |
| else |
106 |
0
| wrappedWriter = writer;
|
107 |
| |
108 |
0
| renderBody(wrappedWriter, cycle);
|
109 |
| |
110 |
0
| if (!disabled)
|
111 |
| { |
112 |
| |
113 |
0
| renderInformalParameters(writer, cycle);
|
114 |
| |
115 |
| |
116 |
0
| wrappedWriter.close();
|
117 |
| |
118 |
| |
119 |
0
| writer.end();
|
120 |
| } |
121 |
| } |
122 |
| |
123 |
| |
124 |
| |
125 |
| |
126 |
0
| protected void prepareForRender(IRequestCycle cycle)
|
127 |
| { |
128 |
0
| if (cycle.getAttribute(ATTRIBUTE_NAME) != null)
|
129 |
0
| throw new ApplicationRuntimeException(Tapestry.getMessage("LinkSubmit.may-not-nest"),
|
130 |
| this, null, null); |
131 |
| |
132 |
0
| cycle.setAttribute(ATTRIBUTE_NAME, this);
|
133 |
| } |
134 |
| |
135 |
| |
136 |
| |
137 |
| |
138 |
0
| protected void cleanupAfterRender(IRequestCycle cycle)
|
139 |
| { |
140 |
0
| cycle.removeAttribute(ATTRIBUTE_NAME);
|
141 |
| } |
142 |
| } |