View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/DbSearchCheckBoxTag.java,v 1.9 2006/03/25 15:37:44 nicparise Exp $
3    * $Revision: 1.9 $
4    * $Date: 2006/03/25 15:37:44 $
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.Field;
27  
28  import org.dbforms.util.Util;
29  
30  import javax.servlet.jsp.JspException;
31  
32  
33  
34  /***
35   * <p>
36   * renders a input field for searching with special default search modes.
37   * </p>
38   *
39   * <p>
40   * example:
41   * </p>
42   * &lt;input type="hidden" name="searchalgo_0_1" value="weakEnd"/&gt; &lt;input
43   * type="hidden" name="searchmode_0_1" value="AND"/&gt; &lt;input type="text"
44   * name="search_0_1"/&gt; searchalgo and searchmode are set by parameter.
45   *
46   * @author Henner Kollmann
47   */
48  public class DbSearchCheckBoxTag extends DbSearchTag
49     implements javax.servlet.jsp.tagext.TryCatchFinally {
50     private String checked = "false";
51     private String value = null;
52  
53     /***
54      * DOCUMENT ME!
55      *
56      * @param string
57      */
58     public void setChecked(String string) {
59        checked = string;
60     }
61  
62  
63     /***
64      * DOCUMENT ME!
65      *
66      * @return
67      */
68     public String getChecked() {
69        return checked;
70     }
71  
72  
73     /***
74      * DOCUMENT ME!
75      *
76      * @param string
77      */
78     public void setValue(String string) {
79        value = string;
80     }
81  
82  
83     /***
84      * DOCUMENT ME!
85      *
86      * @return
87      */
88     public String getValue() {
89        return value;
90     }
91  
92     /***
93      * DOCUMENT ME!
94      *
95      * @return DOCUMENT ME!
96      *
97      * @throws javax.servlet.jsp.JspException DOCUMENT ME!
98      * @throws JspException DOCUMENT ME!
99      */
100    public int doEndTag() throws javax.servlet.jsp.JspException {
101       try {
102          Field field = getField();
103 
104          /*
105                             <input type="hidden" name="searchalgo_0_1" value="weakEnd"/>
106                             <input type="hidden" name="searchmode_0_1" value="AND"/>
107                             <input type="text" name="search_0_1"/>
108          */
109          StringBuffer tagBuf = new StringBuffer();
110 
111          StringBuffer paramNameBuf = new StringBuffer();
112          paramNameBuf.append(field.getSearchFieldName());
113 
114          tagBuf.append("<input type=\"checkbox\" name=\"");
115          tagBuf.append(paramNameBuf.toString());
116          tagBuf.append("\" ");
117          tagBuf.append("value=\"");
118          tagBuf.append(getValue());
119 
120          if (Util.getTrue(getChecked())) {
121             tagBuf.append("\" checked=\"checked");
122          }
123 
124          tagBuf.append("\"");
125          tagBuf.append(prepareStyles());
126          tagBuf.append(prepareEventHandlers());
127          tagBuf.append("/>\n");
128 
129          pageContext.getOut()
130                     .write(renderPatternHtmlInputField());
131          pageContext.getOut()
132                     .write(RenderHiddenFields(field));
133          pageContext.getOut()
134                     .write(tagBuf.toString());
135       } catch (java.io.IOException ioe) {
136          throw new JspException("IO Error: " + ioe.getMessage());
137       }
138 
139       return EVAL_PAGE;
140    }
141 
142 
143    /***
144     * DOCUMENT ME!
145     */
146    public void doFinally() {
147       checked = "false";
148       value   = null;
149       super.doFinally();
150    }
151 }