KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > methodhead > transfer > FormTag


1 /*
2  * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
3  *
4  * This file is part of TransferCM.
5  *
6  * TransferCM is free software; you can redistribute it and/or modify it under the
7  * terms of the GNU General Public License as published by the Free Software
8  * Foundation; either version 2 of the License, or (at your option) any later
9  * version.
10  *
11  * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
18  * Fifth Floor, Boston, MA 02110-1301 USA
19  */

20
21 package com.methodhead.transfer;
22
23 import java.io.IOException JavaDoc;
24
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26 import javax.servlet.http.HttpServletResponse JavaDoc;
27 import javax.servlet.http.HttpSession JavaDoc;
28 import javax.servlet.jsp.JspException JavaDoc;
29 import javax.servlet.jsp.JspWriter JavaDoc;
30 import javax.servlet.jsp.PageContext JavaDoc;
31 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
32
33 import org.apache.struts.Globals;
34 import org.apache.struts.action.ActionForm;
35 import org.apache.struts.action.ActionMapping;
36 import org.apache.struts.action.ActionServlet;
37 import org.apache.struts.config.FormBeanConfig;
38 import org.apache.struts.config.ModuleConfig;
39 import org.apache.struts.util.MessageResources;
40 import org.apache.struts.util.RequestUtils;
41 import org.apache.struts.util.ResponseUtils;
42
43 /**
44  * Extends Struts' <code>FormTag</code> to add module attribute, which is used
45  * to lookup the correct <code>ModuleConfig</code>. This situation arises when
46  * extensions, implemented in Struts modules, forward to a shim page (.shtml)
47  * to display their form. Since pages are displayed by PageAction, part of the
48  * root Struts module, the form tag must explicitly be told which module to
49  * look for action mappings in.
50  */

51 public class FormTag
52 extends
53   org.apache.struts.taglib.html.FormTag {
54
55   // constructors /////////////////////////////////////////////////////////////
56

57   // constants ////////////////////////////////////////////////////////////////
58

59   // classes //////////////////////////////////////////////////////////////////
60

61   // methods //////////////////////////////////////////////////////////////////
62

63   /**
64    * Overrides default behaviour to render a relative URL for the action.
65    * This is combined with the base tag inserted by the Shim head tag to make
66    * the proper request.
67    */

68   protected String JavaDoc renderFormStartElement() {
69       HttpServletResponse JavaDoc response =
70           (HttpServletResponse JavaDoc) this.pageContext.getResponse();
71           
72       StringBuffer JavaDoc results = new StringBuffer JavaDoc("<form");
73       results.append(" name=\"");
74       results.append(beanName);
75       results.append("\"");
76       results.append(" method=\"");
77       results.append(method == null ? "post" : method);
78       results.append("\" action=\"");
79
80       //
81
// BEGIN shim hack
82
//
83

84       //
85
// insert the module prefix and print the result as a relative url
86
//
87
ModuleConfig config = ( ModuleConfig )pageContext.getRequest().getAttribute( Globals.MODULE_KEY );
88
89       if (config != null) {
90         results.append( config.getPrefix().substring( 1 ) + "/" );
91       }
92
93       results.append( response.encodeURL( this.action.substring( 1 ) + ".do" ));
94
95       //
96
// END shim hack
97
//
98

99       results.append("\"");
100       
101       if (styleClass != null) {
102           results.append(" class=\"");
103           results.append(styleClass);
104           results.append("\"");
105       }
106       if (enctype != null) {
107           results.append(" enctype=\"");
108           results.append(enctype);
109           results.append("\"");
110       }
111       if (onreset != null) {
112           results.append(" onreset=\"");
113           results.append(onreset);
114           results.append("\"");
115       }
116       if (onsubmit != null) {
117           results.append(" onsubmit=\"");
118           results.append(onsubmit);
119           results.append("\"");
120       }
121       if (style != null) {
122           results.append(" style=\"");
123           results.append(style);
124           results.append("\"");
125       }
126       if (styleId != null) {
127           results.append(" id=\"");
128           results.append(styleId);
129           results.append("\"");
130       }
131       if (target != null) {
132           results.append(" target=\"");
133           results.append(target);
134           results.append("\"");
135       }
136       results.append(">");
137       return results.toString();
138   }
139
140   // properties ///////////////////////////////////////////////////////////////
141

142   // attributes ///////////////////////////////////////////////////////////////
143
}
144
Popular Tags