1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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.8 $
43 */
44 public class HasRecordsTag 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 * DOCUMENT ME!
82 *
83 * @return DOCUMENT ME!
84 *
85 * @throws javax.servlet.jsp.JspException DOCUMENT ME!
86 * @throws JspException DOCUMENT ME!
87 */
88 public int doEndTag() throws javax.servlet.jsp.JspException {
89
90 try {
91
92
93
94 int rsvSize = 0;
95 if ((getParentForm() != null) && !ResultSetVector.isNull(getParentForm().getResultSetVector())) {
96 rsvSize = getParentForm()
97 .getResultSetVector()
98 .size();
99 }
100
101
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
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 }