KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > servlet > tags > BindErrorsTag


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.web.servlet.tags;
18
19 import javax.servlet.ServletException JavaDoc;
20 import javax.servlet.jsp.JspException JavaDoc;
21 import javax.servlet.jsp.PageContext JavaDoc;
22
23 import org.springframework.validation.Errors;
24 import org.springframework.web.util.ExpressionEvaluationUtils;
25
26 /**
27  * Evaluates content if there are bind errors for a certain bean.
28  * Exports an "errors" variable of type Errors for the given bean.
29  *
30  * @author Rod Johnson
31  * @author Juergen Hoeller
32  * @see BindTag
33  * @see org.springframework.validation.Errors
34  */

35 public class BindErrorsTag extends HtmlEscapingAwareTag {
36
37     public static final String JavaDoc ERRORS_VARIABLE_NAME = "errors";
38
39
40     private String JavaDoc name;
41
42     private Errors errors;
43
44
45     /**
46      * Set the name of the bean that this tag should check.
47      */

48     public void setName(String JavaDoc name) {
49         this.name = name;
50     }
51
52     /**
53      * Return the name of the bean that this tag checks.
54      */

55     public String JavaDoc getName() {
56         return name;
57     }
58
59
60     protected final int doStartTagInternal() throws ServletException JavaDoc, JspException JavaDoc {
61         String JavaDoc resolvedName = ExpressionEvaluationUtils.evaluateString("name", this.name, pageContext);
62         this.errors = getRequestContext().getErrors(resolvedName, isHtmlEscape());
63         if (this.errors != null && this.errors.hasErrors()) {
64             this.pageContext.setAttribute(ERRORS_VARIABLE_NAME, this.errors, PageContext.REQUEST_SCOPE);
65             return EVAL_BODY_INCLUDE;
66         }
67         else {
68             return SKIP_BODY;
69         }
70     }
71
72     public int doEndTag() {
73         this.pageContext.removeAttribute(ERRORS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
74         return EVAL_PAGE;
75     }
76
77     /**
78      * Retrieve the Errors instance that this tag is currently bound to.
79      * Intended for cooperating nesting tags.
80      */

81     public final Errors getErrors() {
82         return errors;
83     }
84
85
86     public void doFinally() {
87         super.doFinally();
88         this.errors = null;
89     }
90
91 }
92
Popular Tags