Source Code Cross Referenced for AutomaticTagFormElementTag.java in  » Web-Framework » aranea-mvc-1.1.1 » org » araneaframework » jsp » tag » uilib » form » element » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » aranea mvc 1.1.1 » org.araneaframework.jsp.tag.uilib.form.element 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright 2006 Webmedia Group Ltd.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *  http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         **/package org.araneaframework.jsp.tag.uilib.form.element;
016:
017:        import java.io.Writer;
018:        import java.lang.reflect.Method;
019:        import java.util.Iterator;
020:        import java.util.Map;
021:        import javax.servlet.jsp.JspException;
022:        import org.araneaframework.core.util.ClassLoaderUtil;
023:        import org.araneaframework.http.JspContext;
024:        import org.araneaframework.jsp.exception.MissingFormElementIdAraneaJspException;
025:        import org.araneaframework.jsp.support.FormElementViewSelector;
026:        import org.araneaframework.jsp.support.TagInfo;
027:        import org.araneaframework.jsp.tag.BaseTag;
028:        import org.araneaframework.jsp.tag.uilib.form.FormElementTag;
029:        import org.araneaframework.jsp.tag.uilib.form.FormElementTagInterface;
030:        import org.araneaframework.jsp.tag.uilib.form.FormTag;
031:        import org.araneaframework.jsp.util.JspWidgetUtil;
032:        import org.araneaframework.uilib.form.Control;
033:        import org.araneaframework.uilib.form.FormElement;
034:        import org.araneaframework.uilib.form.FormWidget;
035:
036:        /**
037:         * Automatic form element tag. Chooses the tag to draw the control based on the information supplied in the 
038:         * component.
039:         * 
040:         * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
041:         * 
042:         * @jsp.tag
043:         *   name = "automaticFormElement"
044:         *   body-content = "JSP"
045:         *   description = "Automatic form element which dynamically draws correct form element tag."
046:         */
047:        public class AutomaticTagFormElementTag extends BaseTag {
048:            protected String derivedId;
049:            private String id;
050:            protected String events;
051:            protected String validateOnEvent;
052:            protected String tabindex;
053:            protected String styleClass;
054:            protected String updateRegions;
055:            protected String globalUpdateRegions;
056:
057:            protected FormWidget.ViewModel formViewModel;
058:
059:            protected FormElement.ViewModel formElementViewModel;
060:            protected Control.ViewModel controlViewModel;
061:
062:            protected FormElementTagInterface controlTag;
063:
064:            protected int doStartTag(Writer out) throws Exception {
065:                super .doStartTag(out);
066:
067:                formViewModel = (FormWidget.ViewModel) requireContextEntry(FormTag.FORM_VIEW_MODEL_KEY);
068:                FormWidget form = (FormWidget) requireContextEntry(FormTag.FORM_KEY);
069:
070:                //In case the tag is in formElement tag
071:                derivedId = id;
072:                if (derivedId == null
073:                        && getContextEntry(FormElementTag.ID_KEY) != null)
074:                    derivedId = (String) getContextEntry(FormElementTag.ID_KEY);
075:                if (derivedId == null)
076:                    throw new MissingFormElementIdAraneaJspException(this );
077:                formElementViewModel = (FormElement.ViewModel) JspWidgetUtil
078:                        .traverseToSubWidget(form, derivedId)._getViewable()
079:                        .getViewModel();
080:
081:                // Get control  
082:                controlViewModel = formElementViewModel.getControl();
083:
084:                FormElementViewSelector viewSelector = (FormElementViewSelector) formElementViewModel
085:                        .getProperties()
086:                        .get(
087:                                FormElementViewSelector.FORM_ELEMENT_VIEW_SELECTOR_PROPERTY);
088:
089:                if (viewSelector == null)
090:                    throw new JspException(
091:                            "The form element view selector was not passed!.");
092:
093:                JspContext config = (JspContext) getEnvironment().requireEntry(
094:                        JspContext.class);
095:                Map tagMapping = config.getTagMapping(viewSelector.getUri());
096:
097:                if (tagMapping == null)
098:                    throw new JspException("The tag mapping was not found!.");
099:
100:                TagInfo tagInfo = (TagInfo) tagMapping.get(viewSelector
101:                        .getTag());
102:
103:                if (tagInfo == null)
104:                    throw new JspException(
105:                            "Unexistant tag was passed to form element view selector!.");
106:
107:                controlTag = (FormElementTagInterface) ClassLoaderUtil
108:                        .loadClass(tagInfo.getTagClassName()).newInstance();
109:                Class tagClass = controlTag.getClass();
110:
111:                registerSubtag(controlTag);
112:
113:                initTagAttributes(tagClass, controlTag, viewSelector
114:                        .getAttributes());
115:
116:                controlTag.setId(derivedId);
117:                if (events != null)
118:                    controlTag.setEvents(events);
119:                if (validateOnEvent != null)
120:                    controlTag.setValidateOnEvent(validateOnEvent);
121:                if (styleClass != null)
122:                    controlTag.setStyleClass(styleClass);
123:                if (tabindex != null)
124:                    controlTag.setTabindex(tabindex);
125:                if (updateRegions != null)
126:                    controlTag.setUpdateRegions(updateRegions);
127:                if (globalUpdateRegions != null)
128:                    controlTag.setGlobalUpdateRegions(globalUpdateRegions);
129:
130:                executeStartSubtag(controlTag);
131:
132:                return EVAL_BODY_INCLUDE;
133:            }
134:
135:            protected int doEndTag(Writer out) throws Exception {
136:                executeEndSubtag(controlTag);
137:                unregisterSubtag(controlTag);
138:
139:                return super .doEndTag(out);
140:            }
141:
142:            /* ***********************************************************************************
143:             * Tag attributes
144:             * ***********************************************************************************/
145:
146:            /**
147:             * @jsp.attribute
148:             *   type = "java.lang.String"
149:             *   required = "false"
150:             *   description = "Element id, can also be inherited." 
151:             */
152:            public void setId(String id) throws JspException {
153:                this .id = (String) evaluateNotNull("id", id, String.class);
154:            }
155:
156:            /**
157:             * @jsp.attribute
158:             *   type = "java.lang.String"
159:             *   required = "false"
160:             *   description = "Whether the element will send the events that are registered by server-side (by default "true")." 
161:             */
162:            public void setEvents(String events) throws JspException {
163:                this .events = events;
164:            }
165:
166:            /**
167:             * @jsp.attribute
168:             *   type = "java.lang.String"
169:             *   required = "false"
170:             *   description = "Whether the form will be validated on the client-side when the element generates an event (by default "false")." 
171:             */
172:            public void setValidateOnEvent(String validateOnEvent)
173:                    throws JspException {
174:                this .validateOnEvent = validateOnEvent;
175:            }
176:
177:            /**
178:             * @jsp.attribute
179:             *   type = "java.lang.String"
180:             *   required = "false"
181:             *   description = "Element tabindex." 
182:             */
183:            public void setTabindex(String tabindex) throws JspException {
184:                this .tabindex = tabindex;
185:            }
186:
187:            /**
188:             * @jsp.attribute
189:             *   type = "java.lang.String"
190:             *   required = "false"
191:             *   description = "CSS class without prefix of the dynamically selected tag." 
192:             */
193:            public void setStyleClass(String styleClass) throws JspException {
194:                this .styleClass = styleClass;
195:            }
196:
197:            /**
198:             * @jsp.attribute
199:             *   type = "java.lang.String"
200:             *   required = "false"
201:             *   description = "Enumerates the regions of markup to be updated in this widget scope. Please see <code><ui:updateRegion></code> for details." 
202:             */
203:            public void setUpdateRegions(String updateRegions)
204:                    throws JspException {
205:                this .updateRegions = updateRegions;
206:            }
207:
208:            /**
209:             * @jsp.attribute
210:             *   type = "java.lang.String"
211:             *   required = "false"
212:             *   description = "Enumerates the regions of markup to be updated globally. Please see <code><ui:updateRegion></code> for details." 
213:             */
214:            public void setGlobalUpdateRegions(String globalUpdateRegions)
215:                    throws JspException {
216:                this .globalUpdateRegions = globalUpdateRegions;
217:            }
218:
219:            protected void initTagAttributes(Class tagClass, Object tag,
220:                    Map attributes) throws Exception {
221:                for (Iterator i = attributes.entrySet().iterator(); i.hasNext();) {
222:                    Map.Entry entry = (Map.Entry) i.next();
223:
224:                    String attributeName = (String) entry.getKey();
225:                    String setterMethodName = "set"
226:                            + attributeName.substring(0, 1).toUpperCase()
227:                            + attributeName.substring(1);
228:
229:                    Method setter = tagClass.getMethod(setterMethodName,
230:                            new Class[] { entry.getValue().getClass() });
231:                    setter.invoke(tag, new Object[] { entry.getValue() });
232:                }
233:            }
234:        }
w__w___w__.__ja__v__a___2___s._c_o__m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.