1 18 19 package cowsultants.itracker.web.taglib; 20 21 import javax.servlet.*; 22 import javax.servlet.http.*; 23 import javax.servlet.jsp.JspException ; 24 import javax.servlet.jsp.tagext.TagSupport ; 25 26 import org.apache.struts.Globals; 27 import org.apache.struts.action.*; 28 29 public final class AddErrorTag extends TagSupport { 30 private String name = Globals.ERROR_KEY; 31 private String key; 32 33 public String getName() { 34 return name; 35 } 36 37 public void setName(String value) { 38 name = value; 39 } 40 41 public String getKey() { 42 return key; 43 } 44 45 public void setKey(String value) { 46 key = value; 47 } 48 49 public int doStartTag() throws JspException { 50 return (SKIP_BODY); 51 } 52 53 public int doEndTag() throws JspException { 54 ActionErrors errors = null; 55 HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); 56 57 if(request == null || getKey() == null) { 58 return EVAL_PAGE; 59 } 60 61 try { 62 errors = (ActionErrors) request.getAttribute(getName()); 63 } catch(ClassCastException cce) { 64 } 65 66 if(errors == null) { 67 errors = new ActionErrors(); 68 } 69 70 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(getKey())); 71 request.setAttribute(getName(), errors); 72 clearState(); 73 return EVAL_PAGE; 74 } 75 76 public void release() { 77 super.release(); 78 clearState(); 79 } 80 81 private void clearState() { 82 name = Globals.ERROR_KEY; 83 key = null; 84 } 85 } 86 | Popular Tags |