1 16 17 package org.springframework.web.servlet.tags; 18 19 import javax.servlet.ServletException ; 20 import javax.servlet.jsp.JspException ; 21 import javax.servlet.jsp.PageContext ; 22 23 import org.springframework.validation.Errors; 24 import org.springframework.web.util.ExpressionEvaluationUtils; 25 26 35 public class BindErrorsTag extends HtmlEscapingAwareTag { 36 37 public static final String ERRORS_VARIABLE_NAME = "errors"; 38 39 40 private String name; 41 42 private Errors errors; 43 44 45 48 public void setName(String name) { 49 this.name = name; 50 } 51 52 55 public String getName() { 56 return name; 57 } 58 59 60 protected final int doStartTagInternal() throws ServletException , JspException { 61 String 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 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 |