1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.document.web.renderers;
17
18 import java.io.IOException;
19
20 import javax.servlet.jsp.JspException;
21 import javax.servlet.jsp.PageContext;
22 import javax.servlet.jsp.tagext.Tag;
23
24 import org.apache.commons.lang.StringUtils;
25 import org.kuali.ole.sys.context.SpringContext;
26 import org.kuali.rice.core.api.config.property.ConfigurationService;
27 import org.kuali.rice.kns.web.ui.Field;
28 import org.kuali.rice.krad.util.KRADConstants;
29
30
31
32
33 public abstract class FieldRendererBase implements FieldRenderer {
34 private Field field;
35 private String dynamicNameLabel;
36 private int arbitrarilyHighTabIndex = -1;
37 private String onBlur;
38 private boolean showError;
39 private String accessibleTitle;
40 private static String riceImageBase;
41
42
43
44
45
46
47
48 public void setField(Field field) {
49 this.field = field;
50 }
51
52
53
54
55
56
57
58 public Field getField() {
59 return this.field;
60 }
61
62
63
64
65 protected String getFieldName() {
66 if (!StringUtils.isBlank(field.getPropertyPrefix())) return field.getPropertyPrefix()+"."+field.getPropertyName();
67 return field.getPropertyName();
68 }
69
70
71
72
73
74 public void clear() {
75 this.field = null;
76 this.arbitrarilyHighTabIndex = -1;
77 this.onBlur = null;
78 }
79
80
81
82
83
84 protected String getAccessibleTitle() {
85 return accessibleTitle;
86 }
87
88
89
90
91
92 public void setAccessibleTitle(String accessibleTitle) {
93 this.accessibleTitle = accessibleTitle;
94 }
95
96
97
98
99
100
101
102
103 protected void renderQuickFinderIfNecessary(PageContext pageContext, Tag parentTag) throws JspException {
104 if (!StringUtils.isBlank(getField().getQuickFinderClassNameImpl()) && renderQuickfinder()) {
105 QuickFinderRenderer renderer = new QuickFinderRenderer();
106 renderer.setField(getField());
107 renderer.setTabIndex(getQuickfinderTabIndex());
108 renderer.setAccessibleTitle(getField().getFieldLabel());
109 renderer.render(pageContext, parentTag);
110 renderer.clear();
111 }
112 }
113
114
115
116
117
118 protected String buildOnBlur() {
119 if (onBlur == null) {
120 StringBuilder onblur = new StringBuilder();
121 if (!StringUtils.isBlank(getField().getWebOnBlurHandler())) {
122 onblur.append(getField().getWebOnBlurHandler());
123 onblur.append("( this.name");
124 if (!StringUtils.isBlank(getDynamicNameLabel())) {
125 onblur.append(", '");
126 onblur.append(getDynamicNameLabel());
127 onblur.append("'");
128 }
129 onblur.append(" );");
130 }
131 onBlur = onblur.toString();
132 }
133 return onBlur;
134 }
135
136
137
138
139
140 public void overrideOnBlur(String onBlur) {
141 this.onBlur = onBlur;
142 }
143
144
145
146
147 protected String getDynamicNameLabel() {
148 return dynamicNameLabel;
149 }
150
151
152
153
154 public void setDynamicNameLabel(String dynamicNameLabel) {
155 this.dynamicNameLabel = dynamicNameLabel;
156 }
157
158
159
160
161 public void setArbitrarilyHighTabIndex(int tabIndex) {
162 this.arbitrarilyHighTabIndex = tabIndex;
163 }
164
165
166
167
168 protected int getQuickfinderTabIndex() {
169 return arbitrarilyHighTabIndex;
170 }
171
172
173
174
175 public void closeNoWrapSpan(PageContext pageContext, Tag parentTag) throws JspException {
176 try {
177 pageContext.getOut().write("</span>");
178 }
179 catch (IOException ioe) {
180 throw new JspException("Could not render closing of no-wrap span", ioe);
181 }
182 }
183
184
185
186
187 public void openNoWrapSpan(PageContext pageContext, Tag parentTag) throws JspException {
188 try {
189 pageContext.getOut().write("<span class=\"nowrap\">");
190 }
191 catch (IOException ioe) {
192 throw new JspException("Could not render opening of no-wrap span", ioe);
193 }
194 }
195
196
197
198
199
200 public boolean isShowError() {
201 return showError;
202 }
203
204
205
206
207
208 public void setShowError(boolean showError) {
209 this.showError = showError;
210 }
211
212
213
214
215
216
217 protected void renderErrorIcon(PageContext pageContext) throws JspException {
218 try {
219 pageContext.getOut().write(getErrorIconImageTag());
220 }
221 catch (IOException ioe) {
222 throw new JspException("Could not render error icon", ioe);
223 }
224 }
225
226
227
228
229 protected String getErrorIconImageTag() {
230 return "<img src=\""+getErrorIconImageSrc()+"\" alt=\"error\" />";
231 }
232
233
234
235
236 private String getErrorIconImageSrc() {
237 return getRiceImageBase()+"errormark.gif";
238 }
239
240
241
242
243 private String getRiceImageBase() {
244 if (riceImageBase == null) {
245 riceImageBase = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(KRADConstants.EXTERNALIZABLE_IMAGES_URL_KEY);
246 }
247 return riceImageBase;
248 }
249 }