KickJava   Java API By Example, From Geeks To Geeks.

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


1 package fr.improve.struts.taglib.layout;
2
3 import javax.servlet.jsp.JspException JavaDoc;
4 import javax.servlet.jsp.JspWriter JavaDoc;
5 import javax.servlet.jsp.PageContext JavaDoc;
6
7 import fr.improve.struts.taglib.layout.util.NestedHelper;
8 import fr.improve.struts.taglib.layout.util.TagUtils;
9
10 /**
11  * Modified from org.apache.struts.taglib.html.BaseHandlerTag
12  * so that the action which the form is posted can be choosed in function of the button which is clicked.
13  * <br>
14  * The actions must inherit from DispatchAction and the parameter name must be frImproveStrutsTaglibLayoutReqCode
15  * Javascript must be enabled on the client's browser.
16  *
17  * @author: Jean-Noël Ribette
18  */

19 public abstract class BaseHandlerTag extends org.apache.struts.taglib.html.BaseHandlerTag implements LayoutTag {
20     protected String JavaDoc reqCode;
21     protected String JavaDoc value;
22     protected org.apache.struts.taglib.html.BaseHandlerTag tag;
23
24     protected String JavaDoc selectCode;
25     protected String JavaDoc selectName = org.apache.struts.taglib.html.Constants.BEAN_KEY;
26     protected String JavaDoc selectProperty;
27     
28     public int doAfterBody() throws JspException JavaDoc {
29         tag.setBodyContent(bodyContent);
30         return tag.doAfterBody();
31     }
32     public PageContext JavaDoc getPageContext() {
33         return pageContext;
34     }
35     public JspWriter JavaDoc getPreviousOut() {
36         if (bodyContent!=null) return super.getPreviousOut();
37         return null;
38     }
39     public String JavaDoc getReqCode() {
40         return reqCode;
41     }
42 protected String JavaDoc getRequestCode() throws JspException JavaDoc {
43     // specify the default action parameter if Action class is subclass of DispatchAction
44
try {
45         String JavaDoc parameter = FormTag.computeActionParameter(pageContext);
46         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
47         if (parameter != null && reqCode != null) {
48             buffer.append("this.form.elements['");
49             buffer.append(NestedHelper.getAdjustedProperty(parameter, pageContext));
50             buffer.append("'].value='");
51             buffer.append(reqCode);
52             buffer.append("'");
53         }
54         if (selectCode!=null) {
55             buffer.append(";this.form.");
56             buffer.append(selectCode);
57             buffer.append(".value='");
58             buffer.append(fr.improve.struts.taglib.layout.util.LayoutUtils.getBeanFromPageContext(pageContext, selectName, selectProperty));
59             buffer.append("'");
60         }
61         return buffer.toString();
62     } catch (Exception JavaDoc e) {
63         if (reqCode!=null) {
64             JspException JavaDoc jspe = new JspException JavaDoc("BaseHandlerTag - cannot acces the DispatchAction parameter: " + e.getMessage() + "(" + e.getClass().getName() + ")");
65             TagUtils.saveException(pageContext, jspe);
66             throw jspe;
67         }
68     }
69     return "";
70 }
71 /**
72  * Insert the method's description here.
73  * Creation date: (18/09/2001 18:58:57)
74  * @return java.lang.String
75  */

76 public java.lang.String JavaDoc getSelectCode() {
77     return selectCode;
78 }
79 /**
80  * Insert the method's description here.
81  * Creation date: (18/09/2001 18:58:57)
82  * @return java.lang.String
83  */

84 public java.lang.String JavaDoc getSelectName() {
85     return selectName;
86 }
87 /**
88  * Insert the method's description here.
89  * Creation date: (18/09/2001 18:58:57)
90  * @return java.lang.String
91  */

92 public java.lang.String JavaDoc getSelectProperty() {
93     return selectProperty;
94 }
95     public String JavaDoc getValue() {
96         return value;
97     }
98     public void release() {
99         super.release();
100         reqCode = null;
101         value = null;
102
103         selectCode = null;
104         selectName = org.apache.struts.taglib.html.Constants.BEAN_KEY;
105         selectProperty = null;
106     }
107     /**
108      * Set the dispatch action to call when this button clicked.
109      */

110     public void setReqCode(String JavaDoc reqCode) {
111         this.reqCode = reqCode;
112     }
113 /**
114  * Insert the method's description here.
115  * Creation date: (18/09/2001 18:58:57)
116  * @param newSelectCode java.lang.String
117  */

118 public void setSelectCode(java.lang.String JavaDoc newSelectCode) {
119     selectCode = newSelectCode;
120 }
121 /**
122  * Insert the method's description here.
123  * Creation date: (18/09/2001 18:58:57)
124  * @param newSelectName java.lang.String
125  */

126 public void setSelectName(java.lang.String JavaDoc newSelectName) {
127     selectName = newSelectName;
128 }
129 /**
130  * Insert the method's description here.
131  * Creation date: (18/09/2001 18:58:57)
132  * @param newSelectProperty java.lang.String
133  */

134 public void setSelectProperty(java.lang.String JavaDoc newSelectProperty) {
135     selectProperty = newSelectProperty;
136 }
137     public void setValue(String JavaDoc value) {
138         this.value = value;
139     }
140 }
141
Popular Tags