View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/DbAssociatedRadioTag.java,v 1.15 2006/01/13 13:38:50 hkollmann Exp $
3    * $Revision: 1.15 $
4    * $Date: 2006/01/13 13:38:50 $
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 AbstractDbBaseHandlerTag
74     implements javax.servlet.jsp.tagext.TryCatchFinally {
75     private String name;
76  
77     /***
78      * DOCUMENT ME!
79      *
80      * @param name DOCUMENT ME!
81      */
82     public void setName(String name) {
83        this.name = name;
84     }
85  
86  
87     /***
88      * DOCUMENT ME!
89      *
90      * @return DOCUMENT ME!
91      */
92     public String getName() {
93        return name;
94     }
95  
96  
97  
98     /***
99      * DOCUMENT ME!
100     *
101     * @return DOCUMENT ME!
102     *
103     * @throws javax.servlet.jsp.JspException DOCUMENT ME!
104     * @throws JspException DOCUMENT ME!
105     */
106    public int doEndTag() throws javax.servlet.jsp.JspException {
107       try {
108          StringBuffer tagBuf = new StringBuffer("<input type=\"radio\" name=\"");
109          tagBuf.append(name);
110          tagBuf.append("\" value=\"");
111          tagBuf.append(getParentForm().getTable().getId());
112          tagBuf.append("_");
113          tagBuf.append(getParentForm().getPositionPath());
114 
115          // 20020705-HKK: Set defaultChecked for first row!  
116          tagBuf.append("\"");
117 
118          if (getParentForm()
119                       .getCurrentCount() == 0) {
120             tagBuf.append(" checked=\"true\"");
121          }
122 
123          tagBuf.append("/>");
124          pageContext.getOut()
125                     .write(tagBuf.toString());
126       } catch (java.io.IOException ioe) {
127          throw new JspException("IO Error: " + ioe.getMessage());
128       }
129 
130       return EVAL_PAGE;
131    }
132 
133 
134    /***
135     * DOCUMENT ME!
136     */
137    public void doFinally() {
138       name = null;
139       super.doFinally();
140    }
141 }