KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/DbDeleteButtonTag.java,v 1.23 2004/10/20 10:51:55 hkollmann Exp $
3  * $Revision: 1.23 $
4  * $Date: 2004/10/20 10:51:55 $
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.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 import org.dbforms.config.ResultSetVector;
30
31 import org.dbforms.util.MessageResources;
32
33 import javax.servlet.http.HttpServletRequest JavaDoc;
34 import javax.servlet.jsp.JspException JavaDoc;
35
36
37
38 /**
39  * <p>
40  * This tag renders a Delete Button
41  * </p>
42  *
43  * @author Joachim Peer
44  */

45 public class DbDeleteButtonTag extends DbBaseButtonTag
46    implements javax.servlet.jsp.tagext.TryCatchFinally JavaDoc {
47    private static Log logCat = LogFactory.getLog(DbDeleteButtonTag.class);
48    private static int uniqueID;
49
50    static {
51       uniqueID = 1;
52    }
53
54    private String JavaDoc associatedRadio;
55    private String JavaDoc confirmMessage = null;
56
57    /**
58     * DOCUMENT ME!
59     *
60     * @param associatedRadio DOCUMENT ME!
61     */

62    public void setAssociatedRadio(String JavaDoc associatedRadio) {
63       this.associatedRadio = associatedRadio;
64    }
65
66
67    /**
68     * DOCUMENT ME!
69     *
70     * @return DOCUMENT ME!
71     */

72    public String JavaDoc getAssociatedRadio() {
73       return associatedRadio;
74    }
75
76
77    /**
78     * DOCUMENT ME!
79     *
80     * @param confirmMessage DOCUMENT ME!
81     */

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

92    public String JavaDoc getConfirmMessage() {
93       return confirmMessage;
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    public void doFinally() {
109       confirmMessage = null;
110       associatedRadio = null;
111       super.doFinally();
112    }
113
114
115    /**
116     * DOCUMENT ME!
117     *
118     * @return DOCUMENT ME!
119     *
120     * @throws javax.servlet.jsp.JspException DOCUMENT ME!
121     * @throws JspException DOCUMENT ME!
122     */

123    public int doStartTag() throws javax.servlet.jsp.JspException JavaDoc {
124       super.doStartTag();
125
126       DbDeleteButtonTag.uniqueID++; // make sure that we don't mix up buttons
127

128       if (getConfirmMessage() != null) {
129          String JavaDoc onclick = (getOnClick() != null) ? getOnClick()
130                                                  : "";
131
132          if (onclick.lastIndexOf(";") != (onclick.length() - 1)) {
133             onclick += ";"; // be sure javascript end with ";"
134
}
135
136          String JavaDoc message = getConfirmMessage();
137
138          if (getParentForm()
139                       .hasCaptionResourceSet()) {
140             try {
141                message = MessageResources.getMessage((HttpServletRequest JavaDoc) pageContext
142                                                      .getRequest(),
143                                                      getConfirmMessage());
144             } catch (Exception JavaDoc e) {
145                logCat.debug("confirm(" + getCaption() + ") Exception : "
146                             + e.getMessage());
147             }
148          }
149
150          setOnClick(onclick + "return confirm('" + message + "');");
151       }
152
153       if (getParentForm()
154                    .isFooterReached()
155                 && ResultSetVector.isNull(getParentForm().getResultSetVector())) {
156          // 20030521 HKK: Bug fixing, thanks to Michael Slack!
157
return SKIP_BODY;
158       }
159
160       try {
161          // first, determinate the name of the button tag
162
StringBuffer JavaDoc tagNameBuf = new StringBuffer JavaDoc("ac_delete");
163
164          if (associatedRadio != null) {
165             tagNameBuf.append("ar");
166          }
167
168          tagNameBuf.append("_");
169          tagNameBuf.append(getTable().getId());
170
171          if (associatedRadio == null) {
172             tagNameBuf.append("_");
173             tagNameBuf.append(getParentForm().getPositionPath());
174          }
175
176          // PG - Render the name unique
177
tagNameBuf.append("_");
178          tagNameBuf.append(uniqueID);
179
180          String JavaDoc tagName = tagNameBuf.toString();
181
182          // then render it and its associtated data-tags
183
StringBuffer JavaDoc tagBuf = new StringBuffer JavaDoc();
184
185          if (associatedRadio != null) {
186             tagBuf.append(getDataTag(tagName, "arname", associatedRadio));
187          }
188
189          if (getFollowUp() != null) {
190             tagBuf.append(getDataTag(tagName, "fu", getFollowUp()));
191          }
192
193          if (getFollowUpOnError() != null) {
194             tagBuf.append(getDataTag(tagName, "fue", getFollowUpOnError()));
195          }
196
197          tagBuf.append(getButtonBegin());
198          tagBuf.append(" name=\"");
199          tagBuf.append(tagName);
200          tagBuf.append(getButtonEnd());
201
202          pageContext.getOut()
203                     .write(tagBuf.toString());
204       } catch (java.io.IOException JavaDoc ioe) {
205          throw new JspException JavaDoc("IO Error: " + ioe.getMessage());
206       }
207
208       if (getChoosenFlavor() == FLAVOR_MODERN) {
209          return EVAL_BODY_BUFFERED;
210       } else {
211          return SKIP_BODY;
212       }
213    }
214 }
215
Popular Tags