View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/HasNoRecordsTag.java,v 1.16 2006/03/16 20:56:47 hkollmann Exp $
3    * $Revision: 1.16 $
4    * $Date: 2006/03/16 20:56:47 $
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.DbFormsErrors;
27  import org.dbforms.config.ResultSetVector;
28  
29  import org.dbforms.util.Util;
30  
31  import java.io.IOException;
32  
33  import javax.servlet.jsp.JspException;
34  import javax.servlet.jsp.JspWriter;
35  
36  
37  
38  /***
39   * DOCUMENT ME!
40   *
41   * @author $author$
42   * @version $Revision: 1.16 $
43   */
44  public class HasNoRecordsTag extends AbstractDbBaseHandlerTag
45     implements javax.servlet.jsp.tagext.TryCatchFinally {
46     private transient DbFormsErrors errors;
47     private String                  message = null;
48  
49     /***
50      * Sets the message
51      *
52      * @param message The message to set
53      */
54     public void setMessage(String message) {
55        this.message = message;
56     }
57  
58  
59     /***
60      * Gets the message
61      *
62      * @return Returns a String
63      */
64     public String getMessage() {
65        return message;
66     }
67  
68  
69     /***
70      * DOCUMENT ME!
71      *
72      * @param pageContext DOCUMENT ME!
73      */
74     public void setPageContext(final javax.servlet.jsp.PageContext pageContext) {
75        super.setPageContext(pageContext);
76        this.errors = (DbFormsErrors) pageContext.getServletContext()
77                                                 .getAttribute(DbFormsErrors.ERRORS);
78     }
79  
80  
81     /***
82      * DOCUMENT ME!
83      *
84      * @return DOCUMENT ME!
85      *
86      * @throws javax.servlet.jsp.JspException DOCUMENT ME!
87      * @throws JspException DOCUMENT ME!
88      */
89     public int doEndTag() throws javax.servlet.jsp.JspException {
90        // Get result set vector from parent and calculate size
91        try {
92       	 //
93            // 20060117-David Horkoff: Add a check to avoid nullvalue exceptions.
94            //
95       	 int rsvSize = 0;
96       	 if ((getParentForm() != null) && !ResultSetVector.isNull(getParentForm().getResultSetVector())) {
97       		rsvSize = getParentForm()
98                             .getResultSetVector()
99                             .size();
100      	 }
101      	 // End 20060117 patch.
102          if (rsvSize == 0) {
103             if (bodyContent != null) {
104                bodyContent.writeOut(bodyContent.getEnclosingWriter());
105                bodyContent.clearBody();
106             }
107 
108             String pmessage = (errors != null)
109                              ? errors.getXMLErrorMessage(getMessage())
110                              : getMessage();
111 
112             if (!Util.isNull(pmessage)) {
113                // Print the results to our output writer
114                JspWriter writer = pageContext.getOut();
115 
116                try {
117                   writer.print(pmessage);
118                } catch (IOException e) {
119                   throw new JspException(e.toString());
120                }
121             }
122          }
123       } catch (java.io.IOException e) {
124          throw new JspException("IO Error: " + e.getMessage());
125       }
126 
127       return EVAL_PAGE;
128    }
129 
130 
131    /***
132     * DOCUMENT ME!
133     */
134    public void doFinally() {
135       message = null;
136       errors  = null;
137       super.doFinally();
138    }
139 
140 
141    /***
142     * Render the specified error messages if there are any.
143     *
144     * @return DOCUMENT ME!
145     *
146     * @exception JspException if a JSP exception has occurred
147     */
148    public int doStartTag() throws JspException {
149       if (ResultSetVector.isNull(getParentForm().getResultSetVector())) {
150          return EVAL_BODY_BUFFERED;
151       } else {
152          return SKIP_BODY;
153       }
154    }
155 }