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.JspWriter;
22 import javax.servlet.jsp.PageContext;
23 import javax.servlet.jsp.tagext.Tag;
24
25 import org.apache.struts.taglib.html.HiddenTag;
26 import org.kuali.ole.sys.businessobject.AccountingLine;
27 import org.kuali.ole.sys.context.SpringContext;
28 import org.kuali.ole.sys.document.service.AccountingLineRenderingService;
29 import org.kuali.rice.kns.web.ui.Field;
30 import org.springframework.web.util.HtmlUtils;
31
32
33
34
35 public class OverrideFieldRenderer extends FieldRendererBase {
36 private LabelRenderer overrideLabelRenderer = new LabelRenderer();
37 private FieldRenderer overrideFieldRenderer;
38 private HiddenTag overrideHiddenTag = new HiddenTag();
39 private HiddenTag overrideNeededTag = new HiddenTag();
40 private HiddenTag overridePresentTag = new HiddenTag();
41 private boolean readOnly = false;
42 private String overrideNeededProperty;
43 private String overrideNeededValue;
44 private AccountingLine accountingLine;
45 private String storedFieldValue;
46
47
48
49
50
51 public boolean renderQuickfinder() {
52 return false;
53 }
54
55
56
57
58
59 @Override
60 public void clear() {
61 super.clear();
62 overrideLabelRenderer.clear();
63 overrideFieldRenderer = null;
64 clearOverrideHiddenTag();
65 clearOverrideNeededTag();
66 overrideNeededProperty = null;
67 overrideNeededValue = null;
68 storedFieldValue = null;
69 }
70
71
72
73
74 protected void clearOverrideHiddenTag() {
75 overrideHiddenTag.setPageContext(null);
76 overrideHiddenTag.setParent(null);
77 overrideHiddenTag.setProperty(null);
78 overrideHiddenTag.setValue(null);
79 overridePresentTag.setPageContext(null);
80 overridePresentTag.setParent(null);
81 overridePresentTag.setProperty(null);
82 overridePresentTag.setValue(null);
83 }
84
85
86
87
88 protected void clearOverrideNeededTag() {
89 overrideNeededTag.setPageContext(null);
90 overrideNeededTag.setParent(null);
91 overrideNeededTag.setProperty(null);
92 }
93
94
95
96
97
98
99 @Override
100 public void setField(Field overrideField) {
101 super.setField(overrideField);
102 this.overrideNeededProperty = overrideField.getPropertyPrefix()+"."+overrideField.getPropertyName()+"Needed";
103 storedFieldValue = overrideField.getPropertyValue();
104 overrideField.setPropertyValue(null);
105 }
106
107
108
109
110
111 public boolean isReadOnly() {
112 return readOnly;
113 }
114
115
116
117
118
119 public void setReadOnly(boolean readOnly) {
120 this.readOnly = readOnly;
121 }
122
123
124
125
126
127 public String getOverrideNeededValue() {
128 return overrideNeededValue;
129 }
130
131
132
133
134
135 public void setOverrideNeededValue(String overrideNeededValue) {
136 this.overrideNeededValue = overrideNeededValue;
137 }
138
139
140
141
142
143 public AccountingLine getAccountingLine() {
144 return accountingLine;
145 }
146
147
148
149
150
151 public void setAccountingLine(AccountingLine accountingLine) {
152 this.accountingLine = accountingLine;
153 }
154
155
156
157
158
159 public void render(PageContext pageContext, Tag parentTag) throws JspException {
160 if ((readOnly && getField().getPropertyValue().equals("Yes")) || overrideNeededValue.equals("Yes")) {
161 renderOverrideAsNonHidden(pageContext, parentTag);
162 if (!readOnly) {
163 renderOverridePresent(pageContext, parentTag);
164 }
165 } else {
166 }
167 }
168
169
170
171
172 protected String buildLineBreak() {
173 return "<br />";
174 }
175
176
177
178
179 protected String buildNonBreakingSpace() {
180 return " ";
181 }
182
183
184
185
186 protected String buildLabelSpanOpening() {
187 return "<span style=\"font-weight: normal\">";
188 }
189
190
191
192
193 protected String buildLabelSpanClosing() {
194 return "</span>";
195 }
196
197
198
199
200
201
202
203 protected void renderOverrideAsNonHidden(PageContext pageContext, Tag parentTag) throws JspException {
204 JspWriter out = pageContext.getOut();
205 try {
206 out.write(buildLineBreak());
207 openNoWrapSpan(pageContext, parentTag);
208 out.write(buildLabelSpanOpening());
209 overrideLabelRenderer.setLabel(getField().getFieldLabel());
210 overrideLabelRenderer.setRequired(true);
211 overrideLabelRenderer.setReadOnly(false);
212 overrideLabelRenderer.setLabelFor(getField().getPropertyPrefix()+"."+getField().getPropertyName());
213 overrideLabelRenderer.render(pageContext, parentTag);
214 out.write(buildLabelSpanClosing());
215 out.write(buildNonBreakingSpace());
216 overrideFieldRenderer = readOnly ? new ReadOnlyRenderer() : SpringContext.getBean(AccountingLineRenderingService.class).getFieldRendererForField(getField(), accountingLine);
217 if (overrideFieldRenderer instanceof ReadOnlyRenderer) {
218 ((ReadOnlyRenderer)overrideFieldRenderer).setShouldRenderInquiry(false);
219 out.write(": ");
220
221 getField().setPropertyValue(storedFieldValue);
222 }
223 overrideFieldRenderer.setField(getField());
224 overrideFieldRenderer.setArbitrarilyHighTabIndex(getQuickfinderTabIndex());
225 overrideFieldRenderer.render(pageContext, parentTag);
226 closeNoWrapSpan(pageContext, parentTag);
227 }
228 catch (IOException ioe) {
229 throw new JspException("Difficulty rendering override field", ioe);
230 }
231 }
232
233
234
235
236
237
238
239 protected void renderOverrideAsHidden(PageContext pageContext, Tag parentTag) throws JspException {
240 overrideHiddenTag.setPageContext(pageContext);
241 overrideHiddenTag.setParent(parentTag);
242 overrideHiddenTag.setProperty(getField().getPropertyPrefix()+"."+getField().getPropertyName());
243 if (!readOnly && overrideNeededValue.equals("No")) {
244 overrideHiddenTag.setValue("No");
245 } else {
246 overrideHiddenTag.setValue(getField().getPropertyValue());
247 }
248 overrideHiddenTag.doStartTag();
249 overrideHiddenTag.doEndTag();
250 }
251
252
253
254
255
256
257
258 protected void renderOverridePresent(PageContext pageContext, Tag parentTag) throws JspException {
259 overridePresentTag.setPageContext(pageContext);
260 overridePresentTag.setParent(parentTag);
261 overridePresentTag.setProperty(getField().getPropertyPrefix()+"."+getField().getPropertyName()+".present");
262 overridePresentTag.setValue("I'm here yo!");
263 overridePresentTag.doStartTag();
264 overridePresentTag.doEndTag();
265 }
266
267
268
269
270
271
272
273 protected void renderOverrideNeededField(PageContext pageContext, Tag parentTag) throws JspException {
274 overrideNeededTag.setPageContext(pageContext);
275 overrideNeededTag.setParent(parentTag);
276 overrideNeededTag.setProperty(overrideNeededProperty);
277 overrideNeededTag.setValue(overrideNeededValue);
278 overrideNeededTag.doStartTag();
279 overrideNeededTag.doEndTag();
280 }
281 }