KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbforms > taglib > DbSearchTag


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/DbSearchTag.java,v 1.14 2004/10/06 14:36:15 hkollmann Exp $
3  * $Revision: 1.14 $
4  * $Date: 2004/10/06 14:36:15 $
5  *
6  * DbForms - a Rapid Application Development Framework
7  * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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
35 /**
36  * <p>
37  * renders a input field for searching with special default search modes.
38  * </p>
39  *
40  * <p>
41  * example:
42  * </p>
43  * &lt;input type="hidden" name="searchalgo_0_1" value="weakEnd"/&gt; &lt;input
44  * type="hidden" name="searchmode_0_1" value="AND"/&gt; &lt;input type="input"
45  * name="search_0_1"/&gt; searchalgo and searchmode are set by parameter.
46  *
47  * @author Henner Kollmann
48  */

49 public class DbSearchTag extends DbBaseHandlerTag
50    implements javax.servlet.jsp.tagext.TryCatchFinally JavaDoc {
51    private String JavaDoc defaultValue = null;
52    private String JavaDoc searchAlgo = "sharp";
53    private String JavaDoc searchMode = "and";
54
55    /**
56     * DOCUMENT ME!
57     *
58     * @param value DOCUMENT ME!
59     */

60    public void setDefault(String JavaDoc value) {
61       this.defaultValue = value;
62    }
63
64
65    /**
66     * DOCUMENT ME!
67     *
68     * @return DOCUMENT ME!
69     */

70    public String JavaDoc getDefault() {
71       return defaultValue;
72    }
73
74
75    /**
76     * DOCUMENT ME!
77     *
78     * @param searchAlgo DOCUMENT ME!
79     */

80    public void setSearchAlgo(String JavaDoc searchAlgo) {
81       this.searchAlgo = searchAlgo;
82    }
83
84
85    /**
86     * DOCUMENT ME!
87     *
88     * @return DOCUMENT ME!
89     */

90    public String JavaDoc getSearchAlgo() {
91       return searchAlgo;
92    }
93
94
95    /**
96     * DOCUMENT ME!
97     *
98     * @param searchMode DOCUMENT ME!
99     */

100    public void setSearchMode(String JavaDoc searchMode) {
101       this.searchMode = searchMode;
102    }
103
104
105    /**
106     * DOCUMENT ME!
107     *
108     * @return DOCUMENT ME!
109     */

110    public String JavaDoc getSearchMode() {
111       return searchMode;
112    }
113
114
115    /**
116     * @see javax.servlet.jsp.tagext.TryCatchFinally#doCatch(java.lang.Throwable)
117     */

118    public void doCatch(Throwable JavaDoc t) throws Throwable JavaDoc {
119       throw t;
120    }
121
122
123    /**
124     * DOCUMENT ME!
125     *
126     * @return DOCUMENT ME!
127     *
128     * @throws javax.servlet.jsp.JspException DOCUMENT ME!
129     * @throws JspException DOCUMENT ME!
130     */

131    public int doEndTag() throws javax.servlet.jsp.JspException JavaDoc {
132       try {
133          Field field = getField();
134
135          /*
136                             <input type="hidden" name="searchalgo_0_1" value="weakEnd"/>
137                             <input type="hidden" name="searchmode_0_1" value="AND"/>
138                             <input type="input" name="search_0_1"/>
139          */

140          HttpServletRequest request = (HttpServletRequest) pageContext
141                                       .getRequest();
142          StringBuffer JavaDoc tagBuf = new StringBuffer JavaDoc();
143
144          StringBuffer JavaDoc paramNameBuf = new StringBuffer JavaDoc();
145          paramNameBuf.append(field.getSearchFieldName());
146
147          String JavaDoc oldValue = ParseUtil.getParameter(request,
148                                                   paramNameBuf.toString());
149          tagBuf.append("<input type=\"input\" name=\"");
150          tagBuf.append(paramNameBuf.toString());
151          tagBuf.append("\" ");
152
153          tagBuf.append("value=\"");
154
155          if (oldValue != null) {
156             tagBuf.append(oldValue);
157          } else if (defaultValue != null) {
158             tagBuf.append(defaultValue);
159          }
160
161          tagBuf.append("\"");
162          tagBuf.append(prepareStyles());
163          tagBuf.append(prepareEventHandlers());
164          tagBuf.append("/>\n");
165
166          pageContext.getOut()
167                     .write(renderPatternHtmlInputField());
168          pageContext.getOut()
169                     .write(RenderHiddenFields(field));
170          pageContext.getOut()
171                     .write(tagBuf.toString());
172       } catch (java.io.IOException JavaDoc ioe) {
173          throw new JspException("IO Error: " + ioe.getMessage());
174       }
175
176       return EVAL_PAGE;
177    }
178
179    /*
180     * Must be overloaded to get the right fieldName in renderPatternHtmlInputField!
181     */

182    protected String JavaDoc getFormFieldName() {
183        return getField().getSearchFieldName();
184     }
185
186    /**
187     * DOCUMENT ME!
188     */

189    public void doFinally() {
190       searchAlgo = "sharp";
191       searchMode = "and";
192       defaultValue = null;
193       super.doFinally();
194    }
195
196
197    /**
198     * DOCUMENT ME!
199     *
200     * @param f DOCUMENT ME!
201     *
202     * @return DOCUMENT ME!
203     */

204    protected String JavaDoc RenderHiddenFields(Field f) {
205       StringBuffer JavaDoc tagBuf = new StringBuffer JavaDoc();
206       StringBuffer JavaDoc paramNameBufA = new StringBuffer JavaDoc();
207       paramNameBufA.append(f.getSearchAlgoName());
208       tagBuf.append("<input type=\"hidden\" name=\"");
209       tagBuf.append(paramNameBufA.toString());
210       tagBuf.append("\" value=\"");
211       tagBuf.append(getSearchAlgo());
212       tagBuf.append("\"/>\n");
213
214       StringBuffer JavaDoc paramNameBufB = new StringBuffer JavaDoc();
215       paramNameBufB.append(f.getSearchModeName());
216       tagBuf.append("<input type=\"hidden\" name=\"");
217       tagBuf.append(paramNameBufB.toString());
218       tagBuf.append("\" value=\"");
219       tagBuf.append(getSearchMode());
220       tagBuf.append("\"/>\n");
221
222       return tagBuf.toString();
223    }
224 }
225
Popular Tags