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.text.MessageFormat;
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.ole.sys.OLEKeyConstants;
27 import org.kuali.ole.sys.context.SpringContext;
28 import org.kuali.ole.sys.document.web.util.RendererUtil;
29 import org.kuali.rice.core.api.config.property.ConfigurationService;
30 import org.kuali.rice.krad.util.KRADConstants;
31
32
33
34
35 public class QuickFinderRenderer extends FieldRendererBase {
36 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(QuickFinderRenderer.class);
37
38 private int tabIndex = -1;
39
40
41
42
43
44 public int getTabIndex() {
45 return tabIndex;
46 }
47
48
49
50
51
52 public void setTabIndex(int tabIndex) {
53 this.tabIndex = tabIndex;
54 }
55
56
57
58
59
60 public void render(PageContext pageContext, Tag parentTag) throws JspException {
61 JspWriter out = pageContext.getOut();
62 try {
63 out.write(buildQuickFinderHtml(pageContext));
64 } catch (IOException ioe) {
65 throw new JspException("Cannot render quick finder for field "+getField(), ioe);
66 }
67 }
68
69
70
71
72
73
74 protected String buildQuickFinderHtml(PageContext pageContext) {
75 StringBuilder quickFinderHtml = new StringBuilder();
76 quickFinderHtml.append(" <input type=\"image\" ");
77
78 quickFinderHtml.append("name=\"").append(buildQuickFinderName(pageContext)).append("\" ");
79
80 quickFinderHtml.append("src=\"");
81 quickFinderHtml.append(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString("kr.externalizable.images.url"));
82 quickFinderHtml.append("searchicon.gif");
83 quickFinderHtml.append("\" ");
84
85 quickFinderHtml.append("border=\"0\" ");
86
87 quickFinderHtml.append("class=\"tinybutton\" ");
88
89 quickFinderHtml.append("valign=\"middle\" ");
90
91 quickFinderHtml.append("alt=\"");
92 quickFinderHtml.append(getAccessibleTitle());
93 quickFinderHtml.append("\" ");
94
95 quickFinderHtml.append("title=\"");
96 quickFinderHtml.append(getAccessibleTitle());
97 quickFinderHtml.append("\" ");
98
99 if (tabIndex > -1) {
100 quickFinderHtml.append(" tabIndex=\"");
101 quickFinderHtml.append(getTabIndex());
102 quickFinderHtml.append("\"");
103 }
104
105 quickFinderHtml.append("/> ");
106
107 return quickFinderHtml.toString();
108 }
109
110
111
112
113
114 protected String buildQuickFinderName(PageContext pageContext) {
115 StringBuilder nameBuf = new StringBuilder();
116 nameBuf.append("methodToCall.performLookup.");
117
118 nameBuf.append(KRADConstants.METHOD_TO_CALL_BOPARM_LEFT_DEL);
119 nameBuf.append(getField().getQuickFinderClassNameImpl());
120 nameBuf.append(KRADConstants.METHOD_TO_CALL_BOPARM_RIGHT_DEL);
121 nameBuf.append(".");
122
123 nameBuf.append(KRADConstants.METHOD_TO_CALL_PARM1_LEFT_DEL);
124 nameBuf.append(getField().getFieldConversions());
125 nameBuf.append(KRADConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL);
126 nameBuf.append(".");
127
128 nameBuf.append(KRADConstants.METHOD_TO_CALL_PARM2_LEFT_DEL);
129 nameBuf.append(getField().getLookupParameters());
130 nameBuf.append(KRADConstants.METHOD_TO_CALL_PARM2_RIGHT_DEL);
131 nameBuf.append(".");
132
133 nameBuf.append(KRADConstants.METHOD_TO_CALL_PARM3_LEFT_DEL+KRADConstants.METHOD_TO_CALL_PARM3_RIGHT_DEL+".");
134
135 nameBuf.append(KRADConstants.METHOD_TO_CALL_PARM4_LEFT_DEL+KRADConstants.METHOD_TO_CALL_PARM4_RIGHT_DEL+".");
136
137 nameBuf.append(KRADConstants.METHOD_TO_CALL_PARM5_LEFT_DEL+KRADConstants.METHOD_TO_CALL_PARM5_RIGHT_DEL+".");
138
139 nameBuf.append(KRADConstants.METHOD_TO_CALL_PARM7_LEFT_DEL+KRADConstants.METHOD_TO_CALL_PARM7_RIGHT_DEL+".");
140
141 nameBuf.append(KRADConstants.METHOD_TO_CALL_PARM8_LEFT_DEL+KRADConstants.METHOD_TO_CALL_PARM8_RIGHT_DEL+".");
142
143 nameBuf.append(KRADConstants.METHOD_TO_CALL_PARM10_LEFT_DEL);
144 nameBuf.append(getField().getReferencesToRefresh());
145 nameBuf.append(KRADConstants.METHOD_TO_CALL_PARM10_RIGHT_DEL+".");
146
147 nameBuf.append(KRADConstants.METHOD_TO_CALL_PARM9_LEFT_DEL+KRADConstants.METHOD_TO_CALL_PARM9_RIGHT_DEL+".");
148
149 nameBuf.append("anchor");
150
151 String name = nameBuf.toString();
152 RendererUtil.registerEditableProperty(pageContext, name);
153 return name;
154 }
155
156
157
158
159
160 public boolean renderQuickfinder() {
161 return false;
162 }
163
164
165
166
167
168 @Override
169 public void clear() {
170 super.clear();
171 tabIndex = -1;
172 }
173
174
175
176
177
178 @Override
179 public void setAccessibleTitle(String accessibleTitle) {
180 final String messagePattern = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEKeyConstants.LABEL_ACCOUNTING_LINE_QUICKFINDER_ACCESSIBLE_TITLE);
181 final String formattedAccessibleTitle = MessageFormat.format(messagePattern, accessibleTitle);
182 super.setAccessibleTitle(formattedAccessibleTitle);
183 }
184
185 }