KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > view > jsp > form > FormHelper


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.view.jsp.form;
8
9
10 import java.io.IOException JavaDoc;
11
12 import javax.servlet.jsp.JspException JavaDoc;
13 import javax.servlet.jsp.PageContext JavaDoc;
14
15 import com.inversoft.verge.mvc.MVCConstants;
16 import com.inversoft.verge.mvc.controller.form.FormURLTools;
17 import com.inversoft.verge.mvc.view.HtmlViewToolkit;
18
19
20 /**
21  * <p>
22  * This class is a helper for Form MVC custom tags
23  * </p>
24  *
25  * @author Brian Pontarelli
26  * @since 2.0
27  * @version 2.0
28  */

29 public class FormHelper {
30
31     /**
32      * Attempts to cast the given form tag to the Form MVC form tag. If the cast
33      * is successful the cast instance is returned. Otherwise, a JspException is
34      * thrown
35      *
36      * @param formTag The form tag to down cast
37      * @return The tag cast to a FormTag
38      * @throws JspException If the cast fails
39      */

40     public static final FormTag getFormTag(com.inversoft.verge.mvc.view.jsp.html.FormTag formTag)
41     throws JspException JavaDoc {
42
43         try {
44             return (FormTag) formTag;
45         } catch (ClassCastException JavaDoc cce) {
46             throw new JspException JavaDoc("Form controller tags must be inside a Form" +
47                 " MVC form tag");
48         }
49     }
50
51
52     /**
53      * Outputs the extra controller information to the JspWriter in the PageContext
54      * given, using the information in the tag given. This assumes that the
55      * handler type is equal to the constant {@link MVCConstants#FORM_NAME
56      * MVCConstants#FORM_NAME}
57      */

58     public static void outputControllerExtra(String JavaDoc name, String JavaDoc action,
59             PageContext JavaDoc pageContext)
60     throws JspException JavaDoc {
61         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
62         String JavaDoc parameter = FormURLTools.generateSubmitParameter(name, action);
63         HtmlViewToolkit.appendHiddenTag(buf, FormURLTools.SUBMIT_PARAMETER,
64             parameter);
65
66         try {
67             pageContext.getOut().print(buf.toString());
68         } catch (IOException JavaDoc ioe) {
69             throw new JspException JavaDoc(ioe);
70         }
71     }
72 }
Popular Tags