View Javadoc

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