1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.nordija.tapestry.bayeux.link;
17
18 import org.apache.hivemind.ApplicationRuntimeException;
19 import org.apache.tapestry.BaseComponent;
20 import org.apache.tapestry.IMarkupWriter;
21 import org.apache.tapestry.IRequestCycle;
22 import org.apache.tapestry.PageRenderSupport;
23 import org.apache.tapestry.TapestryUtils;
24
25 import java.util.HashMap;
26 import java.util.Map;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 public abstract class ClickOnce extends BaseComponent {
42
43 public static final String DEFAULT_FUNCTION_NAME = "singleSubmit";
44
45 public static final String SUBMITFLAG = "ongoingSubmit";
46
47 public abstract String getOnclick();
48
49 public abstract boolean getDisabled();
50
51 public abstract void setFunctionName(String name);
52
53 public abstract String getFunctionName();
54
55 public abstract void setNestedFunctionCall(String nestedFunctionCall);
56
57 public abstract String getNestedFunctionCall();
58
59 public abstract void setIdParameter(String value);
60
61 public abstract String getIdParameter();
62
63 protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) {
64 if (!cycle.isRewinding()) {
65 PageRenderSupport pageRenderSupport = TapestryUtils.getOptionalPageRenderSupport(cycle);
66 if (pageRenderSupport == null) {
67 throw new ApplicationRuntimeException("SingleSubmit component[" + getId()
68 + "] must be contained inside a body component", this, null, null);
69 }
70 if (getOnclick() == null || "".equals(getOnclick())) {
71 setFunctionName(DEFAULT_FUNCTION_NAME);
72 } else {
73 setFunctionName(pageRenderSupport.getUniqueString(DEFAULT_FUNCTION_NAME + "Nested"));
74 }
75 setNestedFunctionCall(extractOnclick(getOnclick()));
76 } else {
77
78
79 setFunctionName(DEFAULT_FUNCTION_NAME);
80 }
81 super.renderComponent(writer, cycle);
82 }
83
84 public Map getScriptSymbols() {
85 Map ret = new HashMap();
86 ret.put("disabled", Boolean.valueOf(getDisabled()));
87 ret.put("submitflagName", SUBMITFLAG);
88 ret.put("functionName", getFunctionName());
89 ret.put("nestedFunctionCall", "".equals(getNestedFunctionCall()) ? null : getNestedFunctionCall());
90 return ret;
91 }
92
93
94
95
96
97
98
99
100
101 protected static String extractOnclick(String onclick) {
102 String result = null;
103 if (onclick != null && !("".equals(onclick))) {
104 result = onclick.trim();
105
106
107
108 if (result.startsWith("return")) {
109 result = result.replaceFirst("return", "");
110 }
111 result = result.trim();
112 }
113 return result;
114 }
115
116 }