KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/DbAssociatedRadioTag.java,v 1.13 2004/08/18 12:26:05 hkollmann Exp $
3  * $Revision: 1.13 $
4  * $Date: 2004/08/18 12:26:05 $
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 javax.servlet.jsp.*;
27
28
29
30 /**
31  * <p>
32  * This tag enables the end-user to define a row by selecting the radio-button
33  * rendered by this tag
34  * </p>
35  *
36  * <p>
37  * This tag enables the end-user to define a row by selecting the radio-button
38  * rendered by this tag
39  * </p>
40  * &lt;tagclass&gt;org.dbforms.taglib.DbAssociatedRadioTag&lt;/tagclass&gt;
41  * &lt;bodycontent&gt;empty&lt;/bodycontent&gt;
42  *
43  * <p>
44  * example: imagine a table customer, which should be listed. the user should
45  * be able to delete a customer.
46  * </p>
47  * in that case the application developer has to alternatives: to put a
48  * "deleteButton" into the body -> this button gets rendered for every row<br>
49  * if the user klicks the button the associated data row gets deleted. the
50  * disadvantage of this method is that multiple buttons must be rendered,
51  * which takes away lots of space and makes layouting more difficult to put
52  * an "associatedRadio" into the body and the "deleteButton" on the footer (or header)<br>
53  * the radio element gets rendered for every row, the deleteButton just once.
54  * if the user wants to delete a row, he/she has to select the radioButton (to
55  * mark the row he/she wants to be deleted) and then to press the
56  * deleteButton.
57  *
58  * <p>
59  * the more buttons you have the better this method is!!
60  * </p>
61  *
62  * <p>
63  * nota bene: you have to tell the delete (or insert, update...) - button that
64  * there is an associated radio button that marks the row the action should be
65  * applied to, by defining the "associatedRadio" attribute of that respective
66  * button
67  * </p>
68  *
69  * <p></p>
70  *
71  * @author Joachim Peer
72  */

73 public class DbAssociatedRadioTag extends DbBaseHandlerTag
74    implements javax.servlet.jsp.tagext.TryCatchFinally JavaDoc {
75    private String JavaDoc name;
76
77    /**
78     * DOCUMENT ME!
79     *
80     * @param name DOCUMENT ME!
81     */

82    public void setName(String JavaDoc name) {
83       this.name = name;
84    }
85
86
87    /**
88     * DOCUMENT ME!
89     *
90     * @return DOCUMENT ME!
91     */

92    public String JavaDoc getName() {
93       return name;
94    }
95
96
97    /**
98     * @see javax.servlet.jsp.tagext.TryCatchFinally#doCatch(java.lang.Throwable)
99     */

100    public void doCatch(Throwable JavaDoc t) throws Throwable JavaDoc {
101       throw t;
102    }
103
104
105    /**
106     * DOCUMENT ME!
107     *
108     * @return DOCUMENT ME!
109     *
110     * @throws javax.servlet.jsp.JspException DOCUMENT ME!
111     * @throws JspException DOCUMENT ME!
112     */

113    public int doEndTag() throws javax.servlet.jsp.JspException JavaDoc {
114       try {
115          StringBuffer JavaDoc tagBuf = new StringBuffer JavaDoc("<input type=\"radio\" name=\"");
116          tagBuf.append(name);
117          tagBuf.append("\" value=\"");
118          tagBuf.append(getParentForm().getTable().getId());
119          tagBuf.append("_");
120          tagBuf.append(getParentForm().getPositionPath());
121
122          // 20020705-HKK: Set defaultChecked for first row!
123
tagBuf.append("\"");
124
125          if (getParentForm()
126                       .getCurrentCount() == 0) {
127             tagBuf.append(" checked=\"true\"");
128          }
129
130          tagBuf.append("/>");
131          pageContext.getOut()
132                     .write(tagBuf.toString());
133       } catch (java.io.IOException JavaDoc ioe) {
134          throw new JspException("IO Error: " + ioe.getMessage());
135       }
136
137       return EVAL_PAGE;
138    }
139
140
141    /**
142     * DOCUMENT ME!
143     */

144    public void doFinally() {
145       name = null;
146       super.doFinally();
147    }
148 }
149
Popular Tags