View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/HasErrorTag.java,v 1.1 2005/02/20 10:27:44 hkollmann Exp $
3    * $Revision: 1.1 $
4    * $Date: 2005/02/20 10:27:44 $
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  /*
25   * the idea for this class was taken from the class ErrorsTag-class of the Apache Struts Project
26   */
27  package org.dbforms.taglib;
28  
29  import org.dbforms.util.Util;
30  
31  import java.util.Vector;
32  
33  import javax.servlet.jsp.JspException;
34  import javax.servlet.jsp.PageContext;
35  import javax.servlet.jsp.tagext.BodyTagSupport;
36  
37  
38  
39  /***
40   * Custom tag that evaluates its body if an Error has occured.
41   *
42   * <p>
43   * Based on ErrorTag and IsWebEvent tag, allows for conditional coding if an
44   * error event occured.
45   * </p>
46   *
47   * @author Neal Katz
48   */
49  public class HasErrorTag extends BodyTagSupport
50     implements javax.servlet.jsp.tagext.TryCatchFinally {
51     //   private String messagePrefix;
52     private String name  = "errors";
53     private String value = "true";
54  
55     /***
56      * DOCUMENT ME!
57      *
58      * @param name DOCUMENT ME!
59      */
60     public void setName(String name) {
61        this.name = name;
62     }
63  
64  
65     /***
66      * DOCUMENT ME!
67      *
68      * @return DOCUMENT ME!
69      */
70     public String getName() {
71        return (this.name);
72     }
73  
74  
75     /***
76      * DOCUMENT ME!
77      *
78      * @param string
79      */
80     public void setValue(String string) {
81        value = string;
82     }
83  
84  
85     /***
86      * DOCUMENT ME!
87      *
88      * @return
89      */
90     public String getValue() {
91        return value;
92     }
93  
94  
95     /***
96      * DOCUMENT ME!
97      *
98      * @param t DOCUMENT ME!
99      *
100     * @throws Throwable DOCUMENT ME!
101     */
102    public void doCatch(Throwable t) throws Throwable {
103       throw t;
104    }
105 
106 
107    /***
108     * DOCUMENT ME!
109     */
110    public void doFinally() {
111       name  = "errors";
112       value = "true";
113    }
114 
115 
116    // ------------------------------------------------------- Public Methods
117 
118    /***
119     * Render the specified error messages if there are any.
120     *
121     * @return DOCUMENT ME!
122     *
123     * @exception JspException if a JSP exception has occurred
124     */
125    public int doStartTag() throws JspException {
126       Vector             originalErrors = (Vector) pageContext.getAttribute(getName(),
127                                                                             PageContext.REQUEST_SCOPE);
128       boolean            haveError = false;
129 
130       haveError = (((originalErrors != null) && (originalErrors.size() > 0)));
131 
132       return (Util.getTrue(value) == haveError) ? EVAL_BODY_INCLUDE
133                                                 : SKIP_BODY;
134    }
135 }