1 7 package com.inversoft.verge.mvc.view.jsp.error; 8 9 10 import java.util.Iterator ; 11 import java.util.List ; 12 13 import javax.servlet.http.HttpServletRequest ; 14 import javax.servlet.jsp.JspException ; 15 import javax.servlet.jsp.tagext.BodyTagSupport ; 16 17 import com.inversoft.error.BasicError; 18 import com.inversoft.util.StringTools; 19 import com.inversoft.verge.mvc.view.jsp.JspTools; 20 import com.inversoft.verge.util.RequestContext; 21 22 23 49 public class ErrorsTag extends BodyTagSupport { 50 51 private String var; 52 private String property; 53 private Iterator iter; 54 private BasicError error; 55 private boolean excludeProperties; 56 57 58 61 public ErrorsTag() { 62 } 63 64 65 72 public String getVar() { 73 return var; 74 } 75 76 83 public void setVar(String var) { 84 this.var = var; 85 } 86 87 92 public String getProperty() { 93 return property; 94 } 95 96 102 public void setProperty(String property) { 103 this.property = property; 104 } 105 106 111 public boolean isExcludeProperties() { 112 return excludeProperties; 113 } 114 115 121 public void setExcludeProperties(boolean excludeProperties) { 122 this.excludeProperties = excludeProperties; 123 } 124 125 133 public int doStartTag() throws JspException { 134 HttpServletRequest request = (HttpServletRequest ) pageContext.getRequest(); 135 RequestContext context = new RequestContext(request); 136 137 if (!context.hasErrors()) { 138 return SKIP_BODY; 139 } 140 141 List list = null; 143 144 if (StringTools.isEmpty(property)) { 145 if (excludeProperties) { 146 list = context.getBasicErrors(); 147 } else { 148 list = context.getAllErrors(); 149 } 150 } else if (!excludeProperties) { 151 property = (String ) JspTools.expand("property", property, String .class, 153 this, pageContext); 154 155 property = ErrorHelper.findPropertyErrors(property, context, pageContext); 156 if (property == null) { 157 return SKIP_BODY; 158 } 159 160 list = context.getPropertyErrors(property); 161 } else { 162 throw new JspException ("You can either specify a property or the " + 163 "excludeProperties flag but not both"); 164 } 165 166 iter = list.iterator(); 167 if (!iter.hasNext()) { 168 return SKIP_BODY; 169 } 170 171 error = (BasicError) iter.next(); 173 pageContext.setAttribute(var, error); 174 175 return EVAL_BODY_INCLUDE; 176 } 177 178 184 public int doAfterBody() throws JspException { 185 186 int ret = SKIP_BODY; 187 if (iter.hasNext()) { 188 189 error = (BasicError) iter.next(); 191 pageContext.setAttribute(var, error); 192 193 ret = EVAL_BODY_AGAIN; 194 } 195 196 return ret; 197 } 198 } | Popular Tags |