KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/DbInsertButtonTag.java,v 1.29 2004/10/20 10:52:00 hkollmann Exp $
3  * $Revision: 1.29 $
4  * $Date: 2004/10/20 10:52:00 $
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.Util;
32
33 import org.dbforms.validation.ValidatorConstants;
34
35 import javax.servlet.jsp.JspException JavaDoc;
36
37
38
39 /**
40  * <p>
41  * this tag renders an "Insert"-button. #fixme - define abstract base class
42  * [should be fixed in release 0.6]
43  * </p>
44  *
45  * @author Joachim Peer
46  */

47 public class DbInsertButtonTag extends DbBaseButtonTag
48    implements javax.servlet.jsp.tagext.TryCatchFinally JavaDoc {
49    private static Log logCat = LogFactory.getLog(DbInsertButtonTag.class
50                                                  .getName());
51    private String JavaDoc showAlways = "false";
52
53    /**
54     * Sets the showAlways.
55     *
56     * @param showAlways The showAlways to set
57     */

58    public void setShowAlways(String JavaDoc showAlways) {
59       this.showAlways = showAlways;
60    }
61
62
63    /**
64     * Returns the showAlways.
65     *
66     * @return String
67     */

68    public String JavaDoc getShowAlways() {
69       return showAlways;
70    }
71
72
73    /**
74     * @see javax.servlet.jsp.tagext.TryCatchFinally#doCatch(java.lang.Throwable)
75     */

76    public void doCatch(Throwable JavaDoc t) throws Throwable JavaDoc {
77       throw t;
78    }
79
80
81    /**
82     * DOCUMENT ME!
83     */

84    public void doFinally() {
85       showAlways = "false";
86       super.doFinally();
87    }
88
89
90    /**
91     * DOCUMENT ME!
92     *
93     * @return DOCUMENT ME!
94     *
95     * @throws javax.servlet.jsp.JspException DOCUMENT ME!
96     * @throws JspException DOCUMENT ME!
97     */

98    public int doStartTag() throws javax.servlet.jsp.JspException JavaDoc {
99       super.doStartTag();
100
101       logCat.info("pos DbInsertButtonTag 1");
102
103       if (!Util.getTrue(showAlways)
104                 && !(getParentForm()
105                               .isFooterReached()
106                 && ResultSetVector.isNull(getParentForm().getResultSetVector()))) {
107          // 20030521 HKK: Bug fixing, thanks to Michael Slack!
108
return SKIP_BODY;
109       }
110
111       /*
112                       if (!parentForm.getFooterReached())
113                               return SKIP_BODY; // contrary to dbUpdate and dbDelete buttons!
114       */

115       logCat.info("pos DbInsertButtonTag 2");
116
117       try {
118          logCat.info("pos DbInsertButtonTag 3");
119
120          StringBuffer JavaDoc tagBuf = new StringBuffer JavaDoc();
121          StringBuffer JavaDoc tagNameBuf = new StringBuffer JavaDoc();
122
123          tagNameBuf.append("ac_insert_");
124          tagNameBuf.append(getTable().getId());
125          tagNameBuf.append("_");
126          tagNameBuf.append(getParentForm().getPositionPathCore());
127
128          // PG - Render the name unique
129
tagNameBuf.append("_");
130          tagNameBuf.append(Integer.toString(getUniqueID()));
131
132          String JavaDoc tagName = tagNameBuf.toString();
133
134          if (getFollowUp() != null) {
135             tagBuf.append(getDataTag(tagName, "fu", getFollowUp()));
136          }
137
138          if (getFollowUpOnError() != null) {
139             tagBuf.append(getDataTag(tagName, "fue", getFollowUpOnError()));
140          }
141
142          //tagBuf.append( getDataTag(tagName, "id", Integer.toString(parentForm.getFrozenCumulatedCount())) );
143
tagBuf.append(getButtonBegin());
144          tagBuf.append(" name=\"");
145          tagBuf.append(tagName);
146          tagBuf.append(getButtonEnd());
147
148          pageContext.getOut()
149                     .write(tagBuf.toString());
150       } catch (java.io.IOException JavaDoc ioe) {
151          throw new JspException JavaDoc("IO Error: " + ioe.getMessage());
152       }
153
154       if (getChoosenFlavor() == FLAVOR_MODERN) {
155          return EVAL_BODY_BUFFERED;
156       } else {
157          return SKIP_BODY;
158       }
159    }
160
161
162    /**
163     * returns the JavaScript validation flags. Will be put into the onClick
164     * event of the main form Must be overloaded by update and delete button
165     *
166     * @return the java script validation vars.
167     */

168    protected String JavaDoc JsValidation() {
169       return (ValidatorConstants.JS_CANCEL_VALIDATION + "=true;"
170              + ValidatorConstants.JS_UPDATE_VALIDATION_MODE + "=false;");
171    }
172 }
173
Popular Tags