Source Code Cross Referenced for ComboBox.java in  » Web-Framework » struts-2.0.11 » org » apache » struts2 » components » 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 » struts 2.0.11 » org.apache.struts2.components 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: ComboBox.java 497654 2007-01-19 00:21:57Z rgielen $
003:         *
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *  http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.
020:         */
021:        package org.apache.struts2.components;
022:
023:        import java.util.Collection;
024:        import java.util.Iterator;
025:        import java.util.Map;
026:
027:        import javax.servlet.http.HttpServletRequest;
028:        import javax.servlet.http.HttpServletResponse;
029:
030:        import org.apache.struts2.views.annotations.StrutsTag;
031:        import org.apache.struts2.views.annotations.StrutsTagAttribute;
032:        import org.apache.struts2.util.MakeIterator;
033:
034:        import com.opensymphony.xwork2.util.ValueStack;
035:
036:        /**
037:         * <!-- START SNIPPET: javadoc -->
038:         * The combo box is basically an HTML INPUT of type text and HTML SELECT grouped together to give you a combo box
039:         * functionality. You can place text in the INPUT control by using the SELECT control or type it in directly in
040:         * the text field.<p/>
041:         *
042:         * In this example, the SELECT will be populated from id=year attribute. Counter is itself an Iterator. It will
043:         * span from first to last. The population is done via javascript, and requires that this tag be surrounded by a
044:         * &lt;form&gt;.<p/>
045:         *
046:         * Note that unlike the &lt;s:select/&gt; tag, there is no ability to define the individual &lt;option&gt; tags' id attribute
047:         * or content separately. Each of these is simply populated from the toString() method of the list item. Presumably
048:         * this is because the select box isn't intended to actually submit useful data, but to assist the user in filling
049:         * out the text field.<p/>
050:         * <!-- END SNIPPET: javadoc -->
051:         *
052:         * <p/> <b>Examples</b>
053:         *
054:         * <pre>
055:         * <!-- START SNIPPET: example -->
056:         * JSP:
057:         * &lt;-- Example One --&gt;
058:         * &lt;s:bean name="struts.util.Counter" id="year"&gt;
059:         *   &lt;s:param name="first" value="text('firstBirthYear')"/&gt;
060:         *   &lt;s:param name="last" value="2000"/&gt;
061:         *
062:         *   &lt;s:combobox label="Birth year" size="6" maxlength="4" name="birthYear" list="#year"/&gt;
063:         * &lt;/s:bean&gt;
064:         *
065:         * &lt;-- Example Two --&gt;
066:         * <s:combobox
067:         *     label="My Favourite Fruit"
068:         *     name="myFavouriteFruit"
069:         *     list="{'apple','banana','grape','pear'}"
070:         *     headerKey="-1"
071:         *     headerValue="--- Please Select ---"
072:         *     emptyOption="true"
073:         *     value="banana" />
074:         *
075:         * &lt;-- Example Two --&gt;
076:         * <s:combobox
077:         *    label="My Favourite Color"
078:         *    name="myFavouriteColor"
079:         *    list="#{'red':'red','green':'green','blue':'blue'}"
080:         *    headerKey="-1"
081:         *    headerValue="--- Please Select ---"
082:         *    emptyOption="true"
083:         *    value="green" />
084:         *
085:         * Velocity:
086:         * #tag( ComboBox "label=Birth year" "size=6" "maxlength=4" "name=birthYear" "list=#year" )
087:         * <!-- END SNIPPET: example -->
088:         * </pre>
089:         *
090:         */
091:        @StrutsTag(name="combobox",tldTagClass="org.apache.struts2.views.jsp.ui.ComboBoxTag",description="Widget that fills a text box from a select")
092:        public class ComboBox extends TextField {
093:            final public static String TEMPLATE = "combobox";
094:
095:            protected String list;
096:            protected String listKey;
097:            protected String listValue;
098:            protected String headerKey;
099:            protected String headerValue;
100:            protected String emptyOption;
101:
102:            public ComboBox(ValueStack stack, HttpServletRequest request,
103:                    HttpServletResponse response) {
104:                super (stack, request, response);
105:            }
106:
107:            protected String getDefaultTemplate() {
108:                return TEMPLATE;
109:            }
110:
111:            public void evaluateExtraParams() {
112:                super .evaluateExtraParams();
113:
114:                Object value = findListValue();
115:
116:                if (headerKey != null) {
117:                    addParameter("headerKey", findString(headerKey));
118:                }
119:                if (headerValue != null) {
120:                    addParameter("headerValue", findString(headerValue));
121:                }
122:                if (emptyOption != null) {
123:                    addParameter("emptyOption", findValue(emptyOption,
124:                            Boolean.class));
125:                }
126:
127:                if (value != null) {
128:                    if (value instanceof  Collection) {
129:                        Collection tmp = (Collection) value;
130:                        addParameter("list", tmp);
131:                        if (listKey != null) {
132:                            addParameter("listKey", listKey);
133:                        }
134:                        if (listValue != null) {
135:                            addParameter("listValue", listValue);
136:                        }
137:                    } else if (value instanceof  Map) {
138:                        Map tmp = (Map) value;
139:                        addParameter("list", MakeIterator.convert(tmp));
140:                        addParameter("listKey", "key");
141:                        addParameter("listValue", "value");
142:                    } else if (value.getClass().isArray()) {
143:                        Iterator i = MakeIterator.convert(value);
144:                        addParameter("list", i);
145:                        if (listKey != null) {
146:                            addParameter("listKey", listKey);
147:                        }
148:                        if (listValue != null) {
149:                            addParameter("listValue", listValue);
150:                        }
151:                    } else {
152:                        Iterator i = MakeIterator.convert(value);
153:                        addParameter("list", i);
154:                        if (listKey != null) {
155:                            addParameter("listKey", listKey);
156:                        }
157:                        if (listValue != null) {
158:                            addParameter("listValue", listValue);
159:                        }
160:                    }
161:                }
162:            }
163:
164:            protected Object findListValue() {
165:                return findValue(list, "list",
166:                        "You must specify a collection/array/map/enumeration/iterator. "
167:                                + "Example: people or people.{name}");
168:            }
169:
170:            @StrutsTagAttribute(description="Iteratable source to populate from. " + "If this is missing, the select widget is simply not displayed.",required=true)
171:            public void setList(String list) {
172:                this .list = list;
173:            }
174:
175:            @StrutsTagAttribute(description="Decide if an empty option is to be inserted. Default false.")
176:            public void setEmptyOption(String emptyOption) {
177:                this .emptyOption = emptyOption;
178:            }
179:
180:            @StrutsTagAttribute(description="Set the header key for the header option.")
181:            public void setHeaderKey(String headerKey) {
182:                this .headerKey = headerKey;
183:            }
184:
185:            @StrutsTagAttribute(description="Set the header value for the header option.")
186:            public void setHeaderValue(String headerValue) {
187:                this .headerValue = headerValue;
188:            }
189:
190:            @StrutsTagAttribute(description="Set the key used to retrive the option key.")
191:            public void setListKey(String listKey) {
192:                this .listKey = listKey;
193:            }
194:
195:            @StrutsTagAttribute(description="Set the value used to retrive the option value.")
196:            public void setListValue(String listValue) {
197:                this.listValue = listValue;
198:            }
199:
200:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.