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.kuali.ole.sys.document.web.util.RendererUtil;
27 import org.kuali.rice.core.api.util.KeyValue;
28
29
30
31
32 public class DropDownRenderer extends FieldRendererBase {
33
34
35
36
37
38 public void render(PageContext pageContext, Tag parentTag) throws JspException {
39 JspWriter out = pageContext.getOut();
40
41 try {
42 out.write(buildSelectControl());
43 renderQuickFinderIfNecessary(pageContext, parentTag);
44 if (isShowError()) {
45 renderErrorIcon(pageContext);
46 }
47 RendererUtil.registerEditableProperty(pageContext, getFieldName());
48 }
49 catch (IOException ioe) {
50 throw new JspException("Difficulty rendering drop down control", ioe);
51 }
52 }
53
54
55
56
57
58
59 protected String buildSelectControl() {
60 StringBuilder selectControl = new StringBuilder();
61 selectControl.append("<select");
62
63 selectControl.append(" id=\"");
64 selectControl.append(getFieldName());
65 selectControl.append("\" ");
66
67 selectControl.append(" name=\"");
68 selectControl.append(getFieldName());
69 selectControl.append("\" ");
70
71 selectControl.append(" title=\"");
72 selectControl.append(this.getAccessibleTitle());
73 selectControl.append("\"");
74
75 final String onBlur = buildOnBlur();
76 if (!StringUtils.isBlank(onBlur)) {
77 selectControl.append(" onblur=\"");
78 selectControl.append(onBlur);
79 selectControl.append("\"");
80 }
81
82 selectControl.append(">");
83
84 selectControl.append(buildOptions());
85
86 selectControl.append("</select>");
87
88 return selectControl.toString();
89 }
90
91
92
93
94
95 protected String buildOptions() {
96 StringBuilder options = new StringBuilder();
97
98 for (Object keyLabelPairAsObj : getField().getFieldValidValues()) {
99 options.append(buildOption((KeyValue)keyLabelPairAsObj));
100 }
101
102 return options.toString();
103 }
104
105
106
107
108
109
110 protected String buildOption(KeyValue keyLabelPair) {
111 StringBuilder option = new StringBuilder();
112
113 option.append("<option value=\"");
114 option.append(keyLabelPair.getKey());
115 option.append("\"");
116 if (getField().getPropertyValue().equalsIgnoreCase(keyLabelPair.getKey().toString())) {
117 option.append(" selected=\"selected\"");
118 }
119 option.append(">");
120
121 option.append(keyLabelPair.getValue());
122
123 option.append("</options>");
124
125 return option.toString();
126 }
127
128
129
130
131
132 public boolean renderQuickfinder() {
133 return false;
134 }
135
136 }