KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > improve > struts > taglib > layout > NotModeTag


1 package fr.improve.struts.taglib.layout;
2
3 import javax.servlet.jsp.JspException JavaDoc;
4 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
5
6 import fr.improve.struts.taglib.layout.util.FormUtilsInterface;
7 import fr.improve.struts.taglib.layout.util.LayoutUtils;
8
9 /**
10  * This tag is based on the struts-layout tag <code>ModeTag</code>
11  * which selectively includes a body based on the form mode. This
12  * tag is the reverse of the <code>ModeTag</code> as it only includes
13  * its body if the specified mode and the current mode do not
14  * match.
15  *
16  * @author gbenis1
17  */

18 public class NotModeTag extends TagSupport JavaDoc {
19     /**
20      * String representation of the Form mode. Can be
21      * "create", "edit" or "inspect".
22      */

23     String JavaDoc value;
24
25     /**
26      * Returns the form mode string value.
27      * @return Form mode string representation.
28      */

29     public String JavaDoc getValue() {
30         return value;
31     }
32
33     /**
34      * Sets the form mode as string.
35      * @param value The form mode to set
36      */

37     public void setValue(String JavaDoc value) {
38         this.value = value;
39     }
40
41     /**
42      * Performs the tag actions. If the mode is not equal
43      * to the specified mode, then the body is included,
44      * otherwise the body is ignored.
45      *
46      * @return EVAL_BODY_INCLUDE if the body is to be included.
47      */

48     public int doStartTag() throws JspException JavaDoc {
49         int mode = LayoutUtils.getSkin(pageContext.getSession()).getFormUtils().getFormDisplayMode(pageContext);
50         int notDesiredMode = -1;
51
52         if ("create".equalsIgnoreCase(value)) {
53             notDesiredMode = FormUtilsInterface.CREATE_MODE;
54         } else if ("edit".equalsIgnoreCase(value)) {
55             notDesiredMode = FormUtilsInterface.EDIT_MODE;
56         } else if ("inspect".equalsIgnoreCase(value)) {
57             notDesiredMode = FormUtilsInterface.INSPECT_MODE;
58         }
59
60         if (notDesiredMode == -1) {
61             throw new JspException JavaDoc(
62                 "Form mode "
63                     + value
64                     + " is not valid. Valid form modes are create, edit and inspect.");
65         }
66
67         if (notDesiredMode != mode) {
68             return EVAL_BODY_INCLUDE;
69         } else {
70             return SKIP_BODY;
71         }
72     }
73
74 }
75
Popular Tags