KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cowsultants > itracker > web > taglib > AddErrorTag


1 /*
2  * This software was designed and created by Jason Carroll.
3  * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4  * The author can be reached at jcarroll@cowsultants.com
5  * ITracker website: http://www.cowsultants.com
6  * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it only under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  */

18
19 package cowsultants.itracker.web.taglib;
20
21 import javax.servlet.*;
22 import javax.servlet.http.*;
23 import javax.servlet.jsp.JspException JavaDoc;
24 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
25
26 import org.apache.struts.Globals;
27 import org.apache.struts.action.*;
28
29 public final class AddErrorTag extends TagSupport JavaDoc {
30     private String JavaDoc name = Globals.ERROR_KEY;
31     private String JavaDoc key;
32
33     public String JavaDoc getName() {
34         return name;
35     }
36
37     public void setName(String JavaDoc value) {
38         name = value;
39     }
40
41     public String JavaDoc getKey() {
42         return key;
43     }
44
45     public void setKey(String JavaDoc value) {
46           key = value;
47     }
48
49     public int doStartTag() throws JspException JavaDoc {
50           return (SKIP_BODY);
51     }
52
53     public int doEndTag() throws JspException JavaDoc {
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 JavaDoc 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