1 16 17 package org.springframework.web.servlet.tags; 18 19 import java.beans.PropertyEditor ; 20 21 import javax.servlet.jsp.JspTagException ; 22 import javax.servlet.jsp.PageContext ; 23 24 import org.springframework.validation.Errors; 25 import org.springframework.web.servlet.support.BindStatus; 26 import org.springframework.web.util.ExpressionEvaluationUtils; 27 28 49 public class BindTag extends HtmlEscapingAwareTag { 50 51 54 public static final String STATUS_VARIABLE_NAME = "status"; 55 56 57 private String path; 58 59 private boolean ignoreNestedPath = false; 60 61 private BindStatus status; 62 63 private Object previousPageStatus; 64 65 private Object previousRequestStatus; 66 67 68 77 public void setPath(String path) { 78 this.path = path; 79 } 80 81 84 public String getPath() { 85 return this.path; 86 } 87 88 92 public void setIgnoreNestedPath(boolean ignoreNestedPath) { 93 this.ignoreNestedPath = ignoreNestedPath; 94 } 95 96 99 public boolean isIgnoreNestedPath() { 100 return this.ignoreNestedPath; 101 } 102 103 104 protected final int doStartTagInternal() throws Exception { 105 String resolvedPath = ExpressionEvaluationUtils.evaluateString("path", getPath(), pageContext); 106 107 if (!isIgnoreNestedPath()) { 108 String nestedPath = (String ) pageContext.getAttribute( 109 NestedPathTag.NESTED_PATH_VARIABLE_NAME, PageContext.REQUEST_SCOPE); 110 if (nestedPath != null) { 111 resolvedPath = nestedPath + resolvedPath; 112 } 113 } 114 115 try { 116 this.status = new BindStatus(getRequestContext(), resolvedPath, isHtmlEscape()); 117 } 118 catch (IllegalStateException ex) { 119 throw new JspTagException (ex.getMessage()); 120 } 121 122 this.previousPageStatus = pageContext.getAttribute(STATUS_VARIABLE_NAME, PageContext.PAGE_SCOPE); 124 this.previousRequestStatus = pageContext.getAttribute(STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE); 125 126 pageContext.removeAttribute(STATUS_VARIABLE_NAME, PageContext.PAGE_SCOPE); 129 pageContext.setAttribute(STATUS_VARIABLE_NAME, this.status, PageContext.REQUEST_SCOPE); 130 131 return EVAL_BODY_INCLUDE; 132 } 133 134 public int doEndTag() { 135 if (this.previousPageStatus != null) { 137 pageContext.setAttribute(STATUS_VARIABLE_NAME, this.previousPageStatus, PageContext.PAGE_SCOPE); 138 } 139 if (this.previousRequestStatus != null) { 140 pageContext.setAttribute(STATUS_VARIABLE_NAME, this.previousRequestStatus, PageContext.REQUEST_SCOPE); 141 } 142 else { 143 pageContext.removeAttribute(STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE); 144 } 145 return EVAL_PAGE; 146 } 147 148 149 156 public final String getProperty() { 157 return this.status.getExpression(); 158 } 159 160 165 public final Errors getErrors() { 166 return this.status.getErrors(); 167 } 168 169 174 public final PropertyEditor getEditor() { 175 return this.status.getEditor(); 176 } 177 178 179 public void doFinally() { 180 super.doFinally(); 181 this.status = null; 182 this.previousPageStatus = null; 183 this.previousRequestStatus = null; 184 } 185 186 } 187 | Popular Tags |