1 7 package com.inversoft.verge.mvc.view.jsp.error; 8 9 10 import javax.servlet.http.HttpServletRequest ; 11 import javax.servlet.jsp.JspException ; 12 import javax.servlet.jsp.tagext.TagSupport ; 13 14 import com.inversoft.verge.mvc.view.jsp.JspTools; 15 import com.inversoft.verge.util.RequestContext; 16 17 18 30 public class HasErrorsTag extends TagSupport { 31 32 private Boolean equals; 33 private String property; 34 private String var; 35 private Object value; 36 37 38 public HasErrorsTag() { 39 } 40 41 42 47 public Boolean getEquals() { 48 return equals; 49 } 50 51 56 public void setEquals(Boolean equals) { 57 this.equals = equals; 58 } 59 60 65 public String getProperty() { 66 return property; 67 } 68 69 74 public void setProperty(String property) { 75 this.property = property; 76 } 77 78 85 public String getVar() { 86 return var; 87 } 88 89 96 public void setVar(String var) { 97 this.var = var; 98 } 99 100 105 public Object getValue() { 106 return value; 107 } 108 109 114 public void setValue(Object value) { 115 this.value = value; 116 } 117 118 125 public int doStartTag() throws JspException { 126 127 HttpServletRequest request = (HttpServletRequest ) pageContext.getRequest(); 128 RequestContext context = new RequestContext(request); 129 130 if (property != null) { 131 property = (String ) JspTools.expand("property", property, 132 String .class, this, pageContext); 133 } 134 135 boolean expr = false; 136 if (property != null) { 137 boolean hasErrors = 138 ErrorHelper.hasPropertyErrors(property, context, pageContext); 139 expr = (hasErrors == equals.booleanValue()); 140 } else { 141 expr = (context.hasErrors() == equals.booleanValue()); 142 } 143 144 if (expr && var != null && value != null) { 146 if (value instanceof String ) { 147 value = JspTools.expand("value", (String ) value, Object .class, 148 this, pageContext); 149 } 150 151 pageContext.setAttribute(var, value); 152 } 153 154 return (expr) ? EVAL_BODY_INCLUDE : SKIP_BODY; 155 } 156 } 157 | Popular Tags |