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 import java.util.List;
20
21 import javax.servlet.jsp.JspException;
22 import javax.servlet.jsp.JspWriter;
23 import javax.servlet.jsp.PageContext;
24 import javax.servlet.jsp.tagext.Tag;
25
26 import org.kuali.rice.kns.web.ui.Field;
27
28
29
30
31 public class MultipleReadOnlyFieldsRenderer implements Renderer {
32 private List<Field> fields;
33 private ReadOnlyRenderer readOnlyRenderer = new ReadOnlyRenderer();
34
35
36
37
38
39 public void clear() {
40 fields = null;
41 }
42
43
44
45
46
47
48 public void render(PageContext pageContext, Tag parentTag) throws JspException {
49 try {
50 JspWriter out = pageContext.getOut();
51 if (fields != null && !fields.isEmpty()) {
52 out.write(beginReadOnlyLayout());
53 for (Field field : fields) {
54 out.write(beginReadOnlyLabel());
55 out.write(renderLabel(field));
56 out.write(endReadOnlyLabel());
57 out.write(beginReadOnlyValue());
58 readOnlyRenderer.setField(field);
59 if (field.getInquiryURL() != null) {
60 readOnlyRenderer.setShouldRenderInquiry(true);
61 }
62 readOnlyRenderer.render(pageContext, parentTag);
63 readOnlyRenderer.clear();
64 out.write(endReadOnlyValue());
65 }
66 out.write(endReadOnlyLayout());
67 } else {
68 out.write(renderEmptyCell());
69 }
70 }
71 catch (IOException ioe) {
72 throw new JspException("Could not render MultipleReadOnlyFields", ioe);
73 }
74 }
75
76
77
78
79 protected String renderEmptyCell() {
80 return " ";
81 }
82
83 protected String beginReadOnlyLayout() {
84 return "<table>";
85 }
86
87 protected String beginReadOnlyLabel() {
88 return "<tr><td width=\"50%\">";
89 }
90
91 protected String endReadOnlyLabel() {
92 return "</td>";
93 }
94
95 protected String beginReadOnlyValue() {
96 return "<td width=\"50%\">";
97 }
98
99 protected String endReadOnlyValue() {
100 return "</td></tr>";
101 }
102
103
104
105
106 protected String renderLabel(Field field) {
107 return field.getFieldLabel();
108 }
109
110 protected String endReadOnlyLayout() {
111 return "</table>";
112 }
113
114
115
116
117
118
119 public List<Field> getFields() {
120 return fields;
121 }
122
123
124
125
126
127
128
129 public void setFields(List<Field> fields) {
130 this.fields = fields;
131 }
132
133 }