1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
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
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 }