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.commons.lang.StringUtils;
26 import org.apache.struts.taglib.html.HiddenTag;
27
28
29
30
31
32
33 public class DynamicReadOnlyRender extends ReadOnlyRenderer {
34
35
36 private HiddenTag shadowInputTag = new HiddenTag();
37
38
39
40
41 public void render(PageContext pageContext, Tag parentTag) throws JspException {
42 JspWriter out = pageContext.getOut();
43
44 try {
45 String value = discoverRenderValue();
46 out.write(buildBeginSpan());
47
48 if (!StringUtils.isEmpty(value)) {
49 if (shouldRenderInquiryLink()) {
50 out.write(buildBeginInquiryLink());
51 }
52 out.write(value);
53 if (shouldRenderInquiryLink()) {
54 out.write(buildEndInquiryLink());
55 }
56 } else {
57 out.write(buildNonBreakingSpace());
58 }
59
60 out.write(buildEndSpan());
61 renderShadowInputTag(pageContext, parentTag);
62 }
63 catch (IOException ioe) {
64 throw new JspException("Difficulty rendering read only field", ioe);
65 }
66 }
67
68
69
70
71
72
73 protected String buildBeginSpan() {
74 StringBuilder beginSpan = new StringBuilder();
75 beginSpan.append("<span id=\"");
76 beginSpan.append(getFieldName());
77 beginSpan.append(".div\">");
78 return beginSpan.toString();
79 }
80
81
82
83
84
85
86 protected void renderShadowInputTag(PageContext pageContext, Tag parentTag) throws JspException {
87 shadowInputTag.setPageContext(pageContext);
88 shadowInputTag.setParent(parentTag);
89 shadowInputTag.setProperty(getFieldName());
90 shadowInputTag.setValue(getField().getPropertyValue());
91 shadowInputTag.doStartTag();
92 shadowInputTag.doEndTag();
93 }
94
95 }