1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.taglib;
25
26 import org.dbforms.config.*;
27
28 import org.dbforms.util.*;
29
30 import javax.servlet.http.*;
31 import javax.servlet.jsp.*;
32
33 /***
34 * <p>
35 * renders a input field for searching with special default search modes.
36 * </p>
37 *
38 * <p>
39 * example:
40 * </p>
41 * <input type="hidden" name="searchalgo_0_1" value="weakEnd"/> <input
42 * type="hidden" name="searchmode_0_1" value="AND"/> <input type="text"
43 * name="search_0_1"/> searchalgo and searchmode are set by parameter.
44 *
45 * @author Henner Kollmann
46 */
47 public class DbSearchTag extends AbstractDbBaseHandlerTag implements
48 javax.servlet.jsp.tagext.TryCatchFinally {
49 private String defaultValue = null;
50
51 private String searchAlgo = "sharp";
52
53 private String searchMode = "and";
54
55 private String hidden = "false";
56
57 /***
58 * DOCUMENT ME!
59 *
60 * @param value
61 * DOCUMENT ME!
62 */
63 public void setDefault(String value) {
64 this.defaultValue = value;
65 }
66
67 /***
68 * DOCUMENT ME!
69 *
70 * @return DOCUMENT ME!
71 */
72 public String getDefault() {
73 return defaultValue;
74 }
75
76 /***
77 * DOCUMENT ME!
78 *
79 * @param searchAlgo
80 * DOCUMENT ME!
81 */
82 public void setSearchAlgo(String searchAlgo) {
83 this.searchAlgo = searchAlgo;
84 }
85
86 /***
87 * DOCUMENT ME!
88 *
89 * @return DOCUMENT ME!
90 */
91 public String getSearchAlgo() {
92 return searchAlgo;
93 }
94
95 /***
96 * DOCUMENT ME!
97 *
98 * @param searchMode
99 * DOCUMENT ME!
100 */
101 public void setSearchMode(String searchMode) {
102 this.searchMode = searchMode;
103 }
104
105 /***
106 * DOCUMENT ME!
107 *
108 * @return DOCUMENT ME!
109 */
110 public String getSearchMode() {
111 return searchMode;
112 }
113
114 /***
115 * DOCUMENT ME!
116 *
117 * @return DOCUMENT ME!
118 *
119 * @throws javax.servlet.jsp.JspException
120 * DOCUMENT ME!
121 * @throws JspException
122 * DOCUMENT ME!
123 */
124 public int doEndTag() throws javax.servlet.jsp.JspException {
125 try {
126 Field field = getField();
127
128
129
130
131
132
133 HttpServletRequest request = (HttpServletRequest) pageContext
134 .getRequest();
135 StringBuffer tagBuf = new StringBuffer();
136
137 StringBuffer paramNameBuf = new StringBuffer();
138 paramNameBuf.append(field.getSearchFieldName());
139
140 String oldValue = ParseUtil.getParameter(request, paramNameBuf
141 .toString());
142
143
144
145 if (Util.getTrue(this.getHidden())) {
146 tagBuf.append("<input type=\"hidden\" name=\"");
147 } else {
148 tagBuf.append("<input type=\"text\" name=\"");
149 }
150
151 tagBuf.append(paramNameBuf.toString());
152 tagBuf.append("\" ");
153
154 tagBuf.append("value=\"");
155
156 if (oldValue != null) {
157 tagBuf.append(oldValue);
158 } else if (defaultValue != null) {
159 tagBuf.append(defaultValue);
160 }
161
162 tagBuf.append("\"");
163 tagBuf.append(prepareStyles());
164 tagBuf.append(prepareEventHandlers());
165 tagBuf.append("/>\n");
166
167 pageContext.getOut().write(renderPatternHtmlInputField());
168 pageContext.getOut().write(RenderHiddenFields(field));
169 pageContext.getOut().write(tagBuf.toString());
170 } catch (java.io.IOException ioe) {
171 throw new JspException("IO Error: " + ioe.getMessage());
172 }
173
174 return EVAL_PAGE;
175 }
176
177
178
179
180
181 protected String getFormFieldName() {
182 return getField().getSearchFieldName();
183 }
184
185 /***
186 * DOCUMENT ME!
187 */
188 public void doFinally() {
189 searchAlgo = "sharp";
190 searchMode = "and";
191 defaultValue = null;
192 super.doFinally();
193 }
194
195 /***
196 * DOCUMENT ME!
197 *
198 * @param f
199 * DOCUMENT ME!
200 *
201 * @return DOCUMENT ME!
202 */
203 protected String RenderHiddenFields(Field f) {
204 StringBuffer tagBuf = new StringBuffer();
205 StringBuffer paramNameBufA = new StringBuffer();
206 paramNameBufA.append(f.getSearchAlgoName());
207 tagBuf.append("<input type=\"hidden\" name=\"");
208 tagBuf.append(paramNameBufA.toString());
209 tagBuf.append("\" value=\"");
210 tagBuf.append(getSearchAlgo());
211 tagBuf.append("\"/>\n");
212
213 StringBuffer paramNameBufB = new StringBuffer();
214 paramNameBufB.append(f.getSearchModeName());
215 tagBuf.append("<input type=\"hidden\" name=\"");
216 tagBuf.append(paramNameBufB.toString());
217 tagBuf.append("\" value=\"");
218 tagBuf.append(getSearchMode());
219 tagBuf.append("\"/>\n");
220
221 return tagBuf.toString();
222 }
223
224 public String getHidden() {
225 return hidden;
226 }
227
228 public void setHidden(String hidden) {
229 this.hidden = hidden;
230 }
231 }