View Javadoc
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 org.itracker.web.taglib;
20  
21  import org.apache.struts.Globals;
22  import org.apache.struts.action.ActionErrors;
23  import org.apache.struts.action.ActionMessage;
24  import org.apache.struts.action.ActionMessages;
25  
26  import javax.servlet.http.HttpServletRequest;
27  import javax.servlet.jsp.JspException;
28  import javax.servlet.jsp.tagext.TagSupport;
29  
30  /**
31   * @deprecated errors should be handled by Action classes, not JSPs!
32   */
33  @Deprecated
34  public final class AddErrorTag extends TagSupport {
35      /**
36       *
37       */
38      private static final long serialVersionUID = 1L;
39      private String name = Globals.ERROR_KEY;
40      private String key;
41  
42      public String getName() {
43          return name;
44      }
45  
46      public void setName(String value) {
47          name = value;
48      }
49  
50      public String getKey() {
51          return key;
52      }
53  
54      public void setKey(String value) {
55          key = value;
56      }
57  
58      public int doStartTag() throws JspException {
59          return (SKIP_BODY);
60      }
61  
62      public int doEndTag() throws JspException {
63          ActionErrors errors = null;
64          HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
65  
66          if (request == null || getKey() == null) {
67              return EVAL_PAGE;
68          }
69  
70          try {
71              errors = (ActionErrors) request.getAttribute(getName());
72          } catch (ClassCastException cce) {
73          }
74  
75          if (errors == null) {
76              errors = new ActionErrors();
77          }
78  
79          errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(getKey()));
80          request.setAttribute(getName(), errors);
81          clearState();
82          return EVAL_PAGE;
83      }
84  
85      public void release() {
86          super.release();
87          clearState();
88      }
89  
90      private void clearState() {
91          name = Globals.ERROR_KEY;
92          key = null;
93      }
94  }