KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Collection JavaDoc;
11 import java.util.Iterator JavaDoc;
12
13 import javax.servlet.jsp.tagext.TagData JavaDoc;
14 import javax.servlet.jsp.tagext.VariableInfo JavaDoc;
15
16 import org.apache.log4j.Logger;
17
18 import com.inversoft.util.StringTools;
19 import com.inversoft.verge.mvc.MVCException;
20 import com.inversoft.verge.mvc.controller.form.FormMVCMetaData;
21 import com.inversoft.verge.mvc.controller.form.config.FormConfig;
22 import com.inversoft.verge.util.WebBean;
23
24
25 /**
26  * Validates that the forms method attribute is either post
27  * or get (case-insensitive) and the form name
28  *
29  * @author Brian Pontarelli
30  */

31 public class FormTei extends com.inversoft.verge.mvc.view.jsp.html.FormTei {
32
33     /**
34      * This classes logger
35      */

36     private static final Logger logger = Logger.getLogger(FormTei.class);
37
38
39     /**
40      * Checks that the form name is valid
41      */

42     public boolean isValid(TagData JavaDoc data) {
43         boolean valid = true;
44         String JavaDoc form = data.getAttributeString("form");
45         if (form != null) {
46             FormMVCMetaData metaData = new FormMVCMetaData(form, null);
47             FormConfig config = null;
48             try {
49                 config = (FormConfig) metaData.findFormConfig(null);
50
51                 Collection JavaDoc formBeans = config.getFormBeans();
52                 String JavaDoc var = data.getAttributeString("var");
53                 if (formBeans.size() > 1 && var != null) {
54                     logger.error("The var attribute of the form tag should " +
55                         "only be used when the form has a single form bean");
56                     valid = false;
57                 }
58             } catch (MVCException mvce) {
59                 logger.error(mvce);
60                 valid = false;
61             }
62         } else {
63             valid = false;
64         }
65
66         // Call the super isValid
67
valid &= super.isValid(data);
68
69         return valid;
70     }
71
72     /**
73      * Returns the variable info for the form bean
74      *
75      * @return A single VariableInfo instance for the form bean
76      */

77     public VariableInfo JavaDoc [] getVariableInfo(TagData JavaDoc data) {
78         String JavaDoc form = data.getAttributeString("form");
79         FormMVCMetaData metaData = new FormMVCMetaData(form, null);
80
81         FormConfig config = null;
82         try {
83             config = (FormConfig) metaData.findFormConfig(null);
84         } catch (MVCException mvce) {
85             logger.fatal(mvce);
86             throw new IllegalArgumentException JavaDoc("Invalid form name: " + form);
87         }
88
89         Collection JavaDoc formBeans = config.getFormBeans();
90         VariableInfo JavaDoc[] infos = new VariableInfo JavaDoc[formBeans.size()];
91         Iterator JavaDoc iter = formBeans.iterator();
92         WebBean webBean;
93         int count = 0;
94         String JavaDoc var = data.getAttributeString("var");
95         while (iter.hasNext()) {
96             webBean = (WebBean) iter.next();
97
98             if (StringTools.isEmpty(var)) {
99                 var = webBean.getID();
100             }
101
102             infos[count] = new VariableInfo JavaDoc(var, webBean.getClassName(), true,
103                 VariableInfo.NESTED);
104         }
105
106         return infos;
107     }
108 }
Popular Tags