View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/DbInsertButtonTag.java,v 1.33 2006/01/13 13:38:51 hkollmann Exp $
3    * $Revision: 1.33 $
4    * $Date: 2006/01/13 13:38:51 $
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.GrantedPrivileges;
30  import org.dbforms.config.ResultSetVector;
31  
32  import org.dbforms.util.Util;
33  
34  import org.dbforms.validation.ValidatorConstants;
35  
36  import javax.servlet.http.HttpServletRequest;
37  import javax.servlet.jsp.JspException;
38  
39  
40  
41  /***
42   * <p>
43   * this tag renders an "Insert"-button. #fixme - define abstract base class
44   * [should be fixed in release 0.6]
45   * </p>
46   *
47   * @author Joachim Peer
48   */
49  public class DbInsertButtonTag extends AbstractDbBaseButtonTag
50     implements javax.servlet.jsp.tagext.TryCatchFinally {
51     private static Log logCat = LogFactory.getLog(DbInsertButtonTag.class
52                                                   .getName());
53     private String     showAlways = "false";
54  
55     /***
56      * Sets the showAlways.
57      *
58      * @param showAlways The showAlways to set
59      */
60     public void setShowAlways(String showAlways) {
61        this.showAlways = showAlways;
62     }
63  
64  
65     /***
66      * Returns the showAlways.
67      *
68      * @return String
69      */
70     public String getShowAlways() {
71        return showAlways;
72     }
73  
74  
75     /***
76      * DOCUMENT ME!
77      */
78     public void doFinally() {
79        showAlways = "false";
80        super.doFinally();
81     }
82  
83  
84     /***
85      * DOCUMENT ME!
86      *
87      * @return DOCUMENT ME!
88      *
89      * @throws javax.servlet.jsp.JspException DOCUMENT ME!
90      * @throws JspException DOCUMENT ME!
91      */
92     public int doStartTag() throws javax.servlet.jsp.JspException {
93        super.doStartTag();
94  
95        logCat.info("pos DbInsertButtonTag 1");
96        /*
97         * 2005-12-12
98         * Philip Grunikiewicz
99         * 
100        * Check table priviledges, if user is not allowed to insert into table - don't show button
101        */
102       if ((getTable() != null) && !getTable().hasUserPrivileg((HttpServletRequest)this.pageContext.getRequest(), GrantedPrivileges.PRIVILEG_INSERT)){
103     	  return SKIP_BODY; 
104       }
105 
106       if (!Util.getTrue(showAlways)
107                 && !(getParentForm()
108                               .isFooterReached()
109                 && ResultSetVector.isNull(getParentForm().getResultSetVector()))) {
110          // 20030521 HKK: Bug fixing, thanks to Michael Slack! 
111          return SKIP_BODY;
112       }
113 
114       /*
115                       if (!parentForm.getFooterReached())
116                               return SKIP_BODY; //  contrary to dbUpdate and dbDelete buttons!
117       */
118       logCat.info("pos DbInsertButtonTag 2");
119 
120       try {
121          logCat.info("pos DbInsertButtonTag 3");
122 
123          StringBuffer tagBuf     = new StringBuffer();
124          StringBuffer tagNameBuf = new StringBuffer();
125 
126          tagNameBuf.append("ac_insert_");
127          tagNameBuf.append(getTable().getId());
128          tagNameBuf.append("_");
129          tagNameBuf.append(getParentForm().getPositionPathCore());
130 
131          // PG - Render the name unique
132          tagNameBuf.append("_");
133          tagNameBuf.append(Integer.toString(getUniqueID()));
134 
135          String tagName = tagNameBuf.toString();
136 
137          if (getFollowUp() != null) {
138             tagBuf.append(getDataTag(tagName, "fu", getFollowUp()));
139          }
140 
141          if (getFollowUpOnError() != null) {
142             tagBuf.append(getDataTag(tagName, "fue", getFollowUpOnError()));
143          }
144 
145          //tagBuf.append( getDataTag(tagName, "id", Integer.toString(parentForm.getFrozenCumulatedCount())) );
146          tagBuf.append(getButtonBegin());
147          tagBuf.append(" name=\"");
148          tagBuf.append(tagName);
149          tagBuf.append(getButtonEnd());
150 
151          pageContext.getOut()
152                     .write(tagBuf.toString());
153       } catch (java.io.IOException ioe) {
154          throw new JspException("IO Error: " + ioe.getMessage());
155       }
156 
157       if (getChoosenFlavor() == FLAVOR_MODERN) {
158          return EVAL_BODY_BUFFERED;
159       } else {
160          return SKIP_BODY;
161       }
162    }
163 
164 
165    /***
166     * returns the JavaScript validation flags. Will be put into the onClick
167     * event of the main form Must be overloaded by update and delete button
168     *
169     * @return the java script validation vars.
170     */
171    protected String JsValidation() {
172       return (ValidatorConstants.JS_CANCEL_VALIDATION + "=true;"
173              + ValidatorConstants.JS_UPDATE_VALIDATION_MODE + "=false;");
174    }
175 }