Source Code Cross Referenced for SelectTag.java in  » Portal » stringbeans-3.5 » com » nabhinc » portlet » mvcportlet » taglib » 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 » Portal » stringbeans 3.5 » com.nabhinc.portlet.mvcportlet.taglib 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * (C) Copyright 2004 Nabh Information Systems, Inc.
003:         *
004:         * All copyright notices regarding Nabh's products MUST remain
005:         * intact in the scripts and in the outputted HTML.
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public License
008:         * as published by the Free Software Foundation; either version 2.1 
009:         * of the License, or (at your option) any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:         * GNU Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
019:         *
020:         */
021:        package com.nabhinc.portlet.mvcportlet.taglib;
022:
023:        import java.io.IOException;
024:
025:        import javax.portlet.PortletException;
026:        import javax.portlet.RenderRequest;
027:        import javax.servlet.jsp.JspException;
028:        import javax.servlet.jsp.JspWriter;
029:
030:        import com.nabhinc.portlet.mvcportlet.core.Constants;
031:        import com.nabhinc.portlet.mvcportlet.core.ControllerPortletConfig;
032:        import com.nabhinc.portlet.mvcportlet.core.Form;
033:        import com.nabhinc.portlet.mvcportlet.core.FormField;
034:        import com.nabhinc.portlet.mvcportlet.core.FormFieldPopulator;
035:        import com.nabhinc.portlet.mvcportlet.core.ValueAndLabel;
036:
037:        /**
038:         * "select" tag that populates itself based on a populator
039:         * configured in portlet-config.xml file. 
040:         * Added 
041:         *
042:         * @author Padmanabh Dabke
043:         * (c) 2004 Nabh Information Systems, Inc. All Rights Reserved.
044:         */
045:        public class SelectTag extends BaseTag {
046:            /**
047:             * 
048:             */
049:            private static final long serialVersionUID = 1L;
050:
051:            /**
052:             * Should multiple selections be allowed.  Any non-null value will
053:             * trigger rendering this.
054:             */
055:            private boolean multiple = false;
056:
057:            /**
058:             * How many available options should be displayed when this element
059:             * is rendered?
060:             */
061:            private String size = null;
062:
063:            /**
064:             * Selection value if it is not supplied by the form parameter.
065:             */
066:            private String selection = null;
067:
068:            /**
069:             * Flag indicating insertion of an empty option in the beginning.
070:             */
071:            private boolean insertEmptyOption = true;
072:
073:            public void release() {
074:                super .release();
075:                this .multiple = false;
076:                this .size = null;
077:                this .selection = null;
078:                this .insertEmptyOption = true;
079:            }
080:
081:            public boolean getMultiple() {
082:                return (this .multiple);
083:            }
084:
085:            public void setMultiple(boolean flag) {
086:                this .multiple = flag;
087:            }
088:
089:            public String getSize() {
090:                return (this .size);
091:            }
092:
093:            public void setSize(String size) {
094:                this .size = size;
095:            }
096:
097:            public String getSelection() {
098:                return (this .selection);
099:            }
100:
101:            public void setSelection(String sel) {
102:                this .selection = sel;
103:            }
104:
105:            public boolean getInsertEmptyOption() {
106:                return insertEmptyOption;
107:            }
108:
109:            public void setInsertEmptyOption(boolean flag) {
110:                this .insertEmptyOption = flag;
111:            }
112:
113:            public int doStartTag() throws JspException {
114:                JspWriter out = pageContext.getOut();
115:                Form form = (Form) pageContext
116:                        .getAttribute(Constants.FORM_ATTRIB);
117:                if (form == null)
118:                    throw new JspException(
119:                            "Failed to find a form within MVCPortlet select element.");
120:                FormField field = form.getField(getName());
121:                if (field == null)
122:                    throw new JspException("Failed to find a field named "
123:                            + getName() + "within MVCPortlet select element.");
124:                FormFieldPopulator pop = field.getPopulator();
125:                if (pop == null)
126:                    throw new JspException("Form field " + field.getName()
127:                            + " must have a populator.");
128:                // if multiple is not specified, then check if it is defined in the FormField.
129:                if (!this .multiple) {
130:                    if (field.isMultiValued())
131:                        this .multiple = true;
132:                }
133:                renderSelectStartElement(out);
134:                writeBody(out, pop);
135:
136:                return (EVAL_BODY_INCLUDE);
137:            }
138:
139:            private void renderSelectStartElement(JspWriter out)
140:                    throws JspException {
141:                try {
142:                    out.print("<select name=\"");
143:                    out.print(getName());
144:                    out.print("\"");
145:                    if (btAccesskey != null) {
146:                        out.print(" accesskey=\"");
147:                        out.print(btAccesskey);
148:                        out.print("\"");
149:                    }
150:                    if (multiple) {
151:                        out.print(" multiple=\"multiple\"");
152:                    }
153:                    if (size != null) {
154:                        out.print(" size=\"");
155:                        out.print(size);
156:                        out.print("\"");
157:                    }
158:                    if (tabindex != null) {
159:                        out.print(" tabindex=\"");
160:                        out.print(tabindex);
161:                        out.print("\"");
162:                    }
163:                    out.print(prepareEventHandlers());
164:                    out.print(prepareStyles());
165:                    out.print(">");
166:                } catch (IOException ioe) {
167:                    throw new JspException("IO exception", ioe);
168:                }
169:
170:            }
171:
172:            /**
173:             * Calculate the match values we will actually be using.
174:             * @throws JspException
175:             */
176:            private void writeBody(JspWriter out, FormFieldPopulator pop)
177:                    throws JspException {
178:                try {
179:                    RenderRequest request = (RenderRequest) pageContext
180:                            .getRequest().getAttribute("javax.portlet.request");
181:                    Object optionsObj = pop.getValue(request);
182:                    if (optionsObj == null)
183:                        return;
184:                    String[] selection = null;
185:                    if (this .multiple) {
186:                        selection = getParamValues(request);
187:                    } else {
188:                        String paramVal = getParamValue(request);
189:                        if (paramVal != null) {
190:                            selection = new String[] { paramVal };
191:                        }
192:                    }
193:                    // if (selection == null) selection = pop.getDefaultSelection(request);
194:                    if (selection == null) {
195:                        if (this .selection == null) {
196:                            selection = pop.getDefaultValues(request);
197:                            if (selection == null)
198:                                selection = new String[0];
199:                        } else {
200:                            selection = new String[] { this .selection };
201:                        }
202:                    }
203:                    if (insertEmptyOption && (!multiple))
204:                        out.print("<option></option>");
205:
206:                    ControllerPortletConfig cpConfig = (ControllerPortletConfig) request
207:                            .getAttribute(Constants.PORTLET_CONFIG_ATTRIB);
208:
209:                    if (optionsObj.getClass().getComponentType().equals(
210:                            String.class)) {
211:                        // We have an array of strings that serves as values as well
212:                        // as labels
213:                        String[] options = (String[]) optionsObj;
214:                        for (int i = 0; i < options.length; i++) {
215:                            out.print("<option value=\"");
216:                            out.print(options[i]);
217:                            out.print("\" ");
218:                            for (int j = 0; j < selection.length; j++) {
219:                                if (selection[j].equals(options[i])) {
220:                                    out.print("selected=\"selected\"");
221:                                    break;
222:                                }
223:                            }
224:                            out.print(">");
225:                            out.print(cpConfig.getLocalizedMessage(options[i],
226:                                    request));
227:                            out.print("</option>");
228:                        }
229:                    } else {
230:                        // We have an array of ValueAndLabel objects
231:                        ValueAndLabel[] options = (ValueAndLabel[]) optionsObj;
232:                        for (int i = 0; i < options.length; i++) {
233:                            out.print("<option value=\"");
234:                            out.print(options[i].getValue());
235:                            out.print("\" ");
236:                            for (int j = 0; j < selection.length; j++) {
237:                                if (selection[j].equals(options[i].getValue())) {
238:                                    out.print("selected=\"selected\"");
239:                                    break;
240:                                }
241:                            }
242:                            out.print(">");
243:                            out.print(cpConfig.getLocalizedMessage(options[i]
244:                                    .getLabel(), request));
245:                            out.print("</option>");
246:                        }
247:
248:                    }
249:                } catch (IOException ioe) {
250:                    error("IOException in SelectTag", ioe);
251:                    throw new JspException("IO exception.", ioe);
252:                } catch (PortletException pe) {
253:                    error("PortletException in SelectTag", pe);
254:                    throw new JspException("Portlet exception", pe);
255:                }
256:            }
257:
258:            /**
259:             * Render the end of select.
260:             *
261:             * @exception JspException if a JSP exception has occurred
262:             */
263:            public int doEndTag() throws JspException {
264:                try {
265:                    JspWriter out = pageContext.getOut();
266:                    out.print("</select>");
267:                    return (EVAL_PAGE);
268:                } catch (IOException ioe) {
269:                    throw new JspException("IO exception.", ioe);
270:                }
271:            }
272:
273:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.