Source Code Cross Referenced for BindTag.java in  » Web-Framework » Strecks » org » strecks » web » tag » 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 » Strecks » org.strecks.web.tag 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005-2006 the original author or authors.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005:         * in compliance with the License. You may obtain a copy of the License at
006:         * 
007:         * http://www.apache.org/licenses/LICENSE-2.0
008:         * 
009:         * Unless requiredSuffix by applicable law or agreed to in writing, software distributed under the License
010:         * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011:         * or implied. See the License for the specific language governing permissions and limitations under
012:         * the License.
013:         */
014:
015:        package org.strecks.web.tag;
016:
017:        import javax.servlet.jsp.JspException;
018:        import javax.servlet.jsp.PageContext;
019:        import javax.servlet.jsp.tagext.TagSupport;
020:
021:        import org.apache.commons.beanutils.PropertyUtils;
022:        import org.apache.commons.logging.Log;
023:        import org.apache.commons.logging.LogFactory;
024:
025:        /**
026:         * Tag which allows variable in page context to be to any of the scopes (request, session, or application) using a
027:         * supplied expression. Useful, for example, for binding the loop variable of an iteration to an action bean property,
028:         * page bean property or view helper property
029:         * 
030:         * @author Phil Zoio
031:         */
032:        public class BindTag extends TagSupport {
033:
034:            Log log = LogFactory.getLog(BindTag.class);
035:
036:            private static final long serialVersionUID = -4230698900508229618L;
037:
038:            /**
039:             * the source page context attribute name
040:             */
041:            private String sourceAttribute;
042:
043:            /**
044:             * the target attribute name. This is the attribute to which the property will be bound
045:             */
046:            private String targetExpression;
047:
048:            /**
049:             * the target scope. Can be "request", "session" or "application"
050:             */
051:            private String targetScope;
052:
053:            // ------------------------------------------------------- Public Methods
054:
055:            public int doStartTag() throws JspException {
056:
057:                Object attribute = pageContext.getAttribute(sourceAttribute);
058:
059:                if (attribute != null) {
060:
061:                    String targetAttribute = null;
062:                    String targetProperty = null;
063:
064:                    int firstDot = targetExpression.indexOf('.');
065:                    if (firstDot == -1) {
066:                        targetAttribute = targetExpression;
067:                    } else {
068:                        targetAttribute = targetExpression.substring(0,
069:                                firstDot);
070:                        targetProperty = targetExpression
071:                                .substring(firstDot + 1);
072:                    }
073:
074:                    Object bean = null;
075:
076:                    if (targetScope == null)
077:                        targetScope = "request";
078:
079:                    if ("page".equals(targetScope)) {
080:                        bean = pageContext.getAttribute(targetAttribute,
081:                                PageContext.PAGE_SCOPE);
082:                    } else if ("request".equals(targetScope)) {
083:                        bean = pageContext.getAttribute(targetAttribute,
084:                                PageContext.REQUEST_SCOPE);
085:                    } else if ("session".equals(targetScope)) {
086:                        bean = pageContext.getAttribute(targetAttribute,
087:                                PageContext.SESSION_SCOPE);
088:                    } else if ("application".equals(targetScope)) {
089:                        bean = pageContext.getAttribute(targetAttribute,
090:                                PageContext.APPLICATION_SCOPE);
091:                    } else {
092:                        throw new IllegalStateException(
093:                                "Invalid scope "
094:                                        + targetScope
095:                                        + ": must be 'request', 'session' or 'application'");
096:                    }
097:
098:                    if (bean == null) {
099:                        log.debug("No bean found for attribute "
100:                                + targetAttribute + " in scope " + targetScope);
101:                    } else {
102:
103:                        // attempt to set property using BeanUtils
104:                        try {
105:                            PropertyUtils.setProperty(bean, targetProperty,
106:                                    attribute);
107:                        } catch (Exception e) {
108:                            throw new JspException("Unable to set property "
109:                                    + targetProperty + " in bean "
110:                                    + bean.getClass().getName()
111:                                    + " with value " + attribute);
112:                        }
113:
114:                    }
115:
116:                }
117:                return (EVAL_BODY_INCLUDE);
118:
119:            }
120:
121:            /**
122:             * Release any acquired resources.
123:             */
124:            public void release() {
125:                super .release();
126:                sourceAttribute = null;
127:                targetExpression = null;
128:                targetScope = null;
129:            }
130:
131:            /* ****** getters and setters ******* */
132:
133:            public void setSourceAttribute(String sourceAttribute) {
134:                this .sourceAttribute = sourceAttribute;
135:            }
136:
137:            public void setTargetExpression(String targetExpression) {
138:                this .targetExpression = targetExpression;
139:            }
140:
141:            public void setTargetScope(String targetScope) {
142:                this.targetScope = targetScope;
143:            }
144:
145:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.