1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts2.dojo.components;
23
24 import java.util.Random;
25
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
28
29 import org.apache.struts2.components.ClosingUIBean;
30 import org.apache.struts2.views.annotations.StrutsTagAttribute;
31 import org.apache.struts2.views.annotations.StrutsTagSkipInheritance;
32
33 import com.opensymphony.xwork2.util.ValueStack;
34
35 /***
36 * AbstractRemoteCallUIBean is superclass for all components dealing with remote
37 * calls.
38 */
39 public abstract class AbstractRemoteBean extends ClosingUIBean implements RemoteBean {
40
41 final private static transient Random RANDOM = new Random();
42
43 protected String href;
44 protected String errorText;
45 protected String executeScripts;
46 protected String loadingText;
47 protected String listenTopics;
48 protected String handler;
49 protected String formId;
50 protected String formFilter;
51 protected String notifyTopics;
52 protected String showErrorTransportText;
53 protected String indicator;
54 protected String showLoadingText;
55 protected String beforeNotifyTopics;
56 protected String afterNotifyTopics;
57 protected String errorNotifyTopics;
58 protected String highlightColor;
59 protected String highlightDuration;
60 protected String separateScripts;
61 protected String transport;
62 protected String parseContent;
63
64 public AbstractRemoteBean(ValueStack stack, HttpServletRequest request,
65 HttpServletResponse response) {
66 super(stack, request, response);
67 }
68
69 public void evaluateExtraParams() {
70 super.evaluateExtraParams();
71
72 if (href != null)
73 addParameter("href", findString(href));
74 if (errorText != null)
75 addParameter("errorText", findString(errorText));
76 if (loadingText != null)
77 addParameter("loadingText", findString(loadingText));
78 if (executeScripts != null)
79 addParameter("executeScripts", findValue(executeScripts, Boolean.class));
80 if (listenTopics != null)
81 addParameter("listenTopics", findValue(listenTopics, String.class));
82 if (notifyTopics != null)
83 addParameter("notifyTopics", findValue(notifyTopics, String.class));
84 if (handler != null)
85 addParameter("handler", findString(handler));
86 if (formId != null)
87 addParameter("formId", findString(formId));
88 if (formFilter != null)
89 addParameter("formFilter", findString(formFilter));
90 if (indicator != null)
91 addParameter("indicator", findString(indicator));
92 if (showErrorTransportText != null)
93 addParameter("showErrorTransportText", findValue(showErrorTransportText, Boolean.class));
94 else
95 addParameter("showErrorTransportText", true);
96 if (showLoadingText != null)
97 addParameter("showLoadingText", findString(showLoadingText));
98 if (beforeNotifyTopics != null)
99 addParameter("beforeNotifyTopics", findString(beforeNotifyTopics));
100 if (afterNotifyTopics != null)
101 addParameter("afterNotifyTopics", findString(afterNotifyTopics));
102 if (errorNotifyTopics != null)
103 addParameter("errorNotifyTopics", findString(errorNotifyTopics));
104 if (highlightColor != null)
105 addParameter("highlightColor", findString(highlightColor));
106 if (highlightDuration != null)
107 addParameter("highlightDuration", findString(highlightDuration));
108 if (separateScripts != null)
109 addParameter("separateScripts", findValue(separateScripts, Boolean.class));
110 if (transport != null)
111 addParameter("transport", findString(transport));
112 if (parseContent != null)
113 addParameter("parseContent", findValue(parseContent, Boolean.class));
114 else
115 addParameter("parseContent", true);
116
117
118 Boolean parseContent = (Boolean)stack.getContext().get(Head.PARSE_CONTENT);
119 boolean generateId = (parseContent != null ? !parseContent : true);
120
121 addParameter("pushId", generateId);
122 if ((this.id == null || this.id.length() == 0) && generateId) {
123
124
125 int nextInt = RANDOM.nextInt();
126 nextInt = nextInt == Integer.MIN_VALUE ? Integer.MAX_VALUE : Math.abs(nextInt);
127 this.id = "widget_" + String.valueOf(nextInt);
128 addParameter("id", this.id);
129 }
130 }
131
132 @Override
133 @StrutsTagSkipInheritance
134 public void setTheme(String theme) {
135 super.setTheme(theme);
136 }
137
138 @Override
139 public String getTheme() {
140 return "ajax";
141 }
142
143 @StrutsTagAttribute(description="Topic that will trigger the remote call")
144 public void setListenTopics(String listenTopics) {
145 this.listenTopics = listenTopics;
146 }
147
148 @StrutsTagAttribute(description="The URL to call to obtain the content. Note: If used with ajax context, the value must be set as an url tag value.")
149 public void setHref(String href) {
150 this.href = href;
151 }
152
153
154 @StrutsTagAttribute(description="The text to display to the user if the is an error fetching the content")
155 public void setErrorText(String errorText) {
156 this.errorText = errorText;
157 }
158
159 @StrutsTagAttribute(description="Javascript code in the fetched content will be executed", type="Boolean", defaultValue="false")
160 public void setExecuteScripts(String executeScripts) {
161 this.executeScripts = executeScripts;
162 }
163
164 @StrutsTagAttribute(description="Text to be shown while content is being fetched", defaultValue="Loading...")
165 public void setLoadingText(String loadingText) {
166 this.loadingText = loadingText;
167 }
168
169
170 @StrutsTagAttribute(description="Javascript function name that will make the request")
171 public void setHandler(String handler) {
172 this.handler = handler;
173 }
174
175
176 @StrutsTagAttribute(description="Function name used to filter the fields of the form.")
177 public void setFormFilter(String formFilter) {
178 this.formFilter = formFilter;
179 }
180
181 @StrutsTagAttribute(description="Form id whose fields will be serialized and passed as parameters")
182 public void setFormId(String formId) {
183 this.formId = formId;
184 }
185
186 @StrutsTagAttribute(description="Comma delimmited list of topics that will published before and after the request, and on errors")
187 public void setNotifyTopics(String notifyTopics) {
188 this.notifyTopics = notifyTopics;
189 }
190
191
192 @StrutsTagAttribute(description="Set whether errors will be shown or not", type="Boolean", defaultValue="true")
193 public void setShowErrorTransportText(String showError) {
194 this.showErrorTransportText = showError;
195 }
196
197 @StrutsTagAttribute(description="Id of element that will be shown while making request")
198 public void setIndicator(String indicator) {
199 this.indicator = indicator;
200 }
201
202 @StrutsTagAttribute(description="Show loading text on targets", type="Boolean", defaultValue="false")
203 public void setShowLoadingText(String showLoadingText) {
204 this.showLoadingText = showLoadingText;
205 }
206
207 @StrutsTagAttribute(description="The css class to use for element")
208 public void setCssClass(String cssClass) {
209 super.setCssClass(cssClass);
210 }
211
212 @StrutsTagAttribute(description="The css style to use for element")
213 public void setCssStyle(String cssStyle) {
214 super.setCssStyle(cssStyle);
215 }
216
217 @StrutsTagAttribute(description="The id to use for the element")
218 public void setId(String id) {
219 super.setId(id);
220 }
221
222 @StrutsTagAttribute(description="The name to set for element")
223 public void setName(String name) {
224 super.setName(name);
225 }
226
227 @StrutsTagAttribute(description="Comma delimmited list of topics that will published after the request(if the request succeeds)")
228 public void setAfterNotifyTopics(String afterNotifyTopics) {
229 this.afterNotifyTopics = afterNotifyTopics;
230 }
231
232 @StrutsTagAttribute(description="Comma delimmited list of topics that will published before the request")
233 public void setBeforeNotifyTopics(String beforeNotifyTopics) {
234 this.beforeNotifyTopics = beforeNotifyTopics;
235 }
236
237 @StrutsTagAttribute(description="Comma delimmited list of topics that will published after the request(if the request fails)")
238 public void setErrorNotifyTopics(String errorNotifyTopics) {
239 this.errorNotifyTopics = errorNotifyTopics;
240 }
241
242 @StrutsTagAttribute(description = "Color used to perform a highlight effect on the elements specified in the 'targets' attribute",
243 defaultValue = "none")
244 public void setHighlightColor(String highlightColor) {
245 this.highlightColor = highlightColor;
246 }
247
248 @StrutsTagAttribute(description = "Duration of highlight effect in milliseconds. Only valid if 'highlightColor' attribute is set",
249 defaultValue = "2000", type="Integer")
250 public void setHighlightDuration(String highlightDuration) {
251 this.highlightDuration = highlightDuration;
252 }
253
254 @StrutsTagAttribute(description="Run scripts in a separate scope, unique for each tag", defaultValue="true")
255 public void setSeparateScripts(String separateScripts) {
256 this.separateScripts = separateScripts;
257 }
258
259 @StrutsTagAttribute(description="Transport used by Dojo to make the request", defaultValue="XMLHTTPTransport")
260 public void setTransport(String transport) {
261 this.transport = transport;
262 }
263
264 @StrutsTagAttribute(description="Parse returned HTML for Dojo widgets", defaultValue="true", type="Boolean")
265 public void setParseContent(String parseContent) {
266 this.parseContent = parseContent;
267 }
268 }