Source Code Cross Referenced for Param.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: Param.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.io.Writer;
024:
025:        import org.apache.struts2.views.annotations.StrutsTag;
026:        import org.apache.struts2.views.annotations.StrutsTagAttribute;
027:        import org.apache.struts2.StrutsException;
028:
029:        import com.opensymphony.xwork2.util.ValueStack;
030:
031:        /**
032:         * <!-- START SNIPPET: javadoc -->
033:         * <p>This tag can be used to parameterize other tags.</p>
034:         * The include tag and bean tag are examples of such tags.
035:         * <p/>
036:         * The parameters can be added with or without a name as key.
037:         * If the tag provides a name attribute the parameters are added using the
038:         * {@link Component#addParameter(String, Object) addParamter} method.
039:         * For unnamed parameters the Tag must implement the {@link UnnamedParametric} interface defined in
040:         * this class (e.g. The TextTag does this).
041:         * <p/>
042:         * This tag has the following two paramters.
043:         * <!-- START SNIPPET: params -->
044:         * <ul>
045:         *      <li>name (String) - the name of the parameter</li>
046:         *      <li>value (Object) - the value of the parameter</li>
047:         * </ul>
048:         * <!-- END SNIPPET: params -->
049:         * <p/>
050:         * <b>Note:</b>
051:         * When you declare the param tag, the value can be defined in either a <tt>value</tt> attribute or
052:         * as text between the start and end tag. Struts behaves a bit different according to these two situations.
053:         * This is best illustrated using an example:
054:         * <br/>&lt;param name="color"&gt;blue&lt;/param&gt; &lt;-- (A) --&gt;
055:         * <br/>&lt;param name="color" value="blue"/&gt; &lt;-- (B) --&gt;
056:         * <br/>In the first situation (A) the value would be evaluated to the stack as a <tt>java.lang.String</tt> object.
057:         * And in situation (B) the value would be evaluated to the stack as a <tt>java.lang.Object</tt> object.
058:         * <br/>For more information see <a href="http://jira.opensymphony.com/browse/WW-808">WW-808</a>.
059:         * <!-- END SNIPPET: javadoc -->
060:         *
061:         * <p/> <b>Examples</b>
062:         * <!-- START SNIPPET: example -->
063:         * <pre>
064:         * &lt;ui:component&gt;
065:         *  &lt;ui:param name="key"     value="[0]"/&gt;
066:         *  &lt;ui:param name="value"   value="[1]"/&gt;
067:         *  &lt;ui:param name="context" value="[2]"/&gt;
068:         * &lt;/ui:component&gt;
069:         * </pre>
070:         * <!-- END SNIPPET: example -->
071:         * <p/>
072:         * <!-- START SNIPPET: exampledescription -->
073:         * where the key will be the identifier and the value the result of an OGNL expression run against the current
074:         * ValueStack.
075:         * <!-- END SNIPPET: exampledescription -->
076:         * <p/>
077:         * This second example demonstrates how the text tag can use parameters from this param tag.
078:         * <!-- START SNIPPET: example2 -->
079:         * <pre>
080:         * &lt;s:text name="cart.total.cost"&gt;
081:         *     &lt;s:param value="#session.cartTotal"/&gt;
082:         * &lt;/s:text&gt;
083:         * </pre>
084:         * <!-- END SNIPPET: example2 -->
085:         * <p/>
086:         *
087:         * @see Include
088:         * @see Bean
089:         * @see Text
090:         *
091:         */
092:        @StrutsTag(name="param",tldTagClass="org.apache.struts2.views.jsp.ParamTag",description="Parametrize other tags")
093:        public class Param extends Component {
094:            protected String name;
095:            protected String value;
096:
097:            public Param(ValueStack stack) {
098:                super (stack);
099:            }
100:
101:            public boolean end(Writer writer, String body) {
102:                Component component = findAncestor(Component.class);
103:                if (value != null) {
104:                    if (component instanceof  UnnamedParametric) {
105:                        ((UnnamedParametric) component)
106:                                .addParameter(findValue(value));
107:                    } else {
108:                        String name = findString(this .name);
109:
110:                        if (name == null) {
111:                            throw new StrutsException(
112:                                    "No name found for following expression: "
113:                                            + name);
114:                        }
115:
116:                        Object value = findValue(this .value);
117:                        component.addParameter(name, value);
118:                    }
119:                } else {
120:                    if (component instanceof  UnnamedParametric) {
121:                        ((UnnamedParametric) component).addParameter(body);
122:                    } else {
123:                        component.addParameter(findString(name), body);
124:                    }
125:                }
126:
127:                return super .end(writer, "");
128:            }
129:
130:            public boolean usesBody() {
131:                return true;
132:            }
133:
134:            @StrutsTagAttribute(description="Name of Parameter to set")
135:            public void setName(String name) {
136:                this .name = name;
137:            }
138:
139:            @StrutsTagAttribute(description="Value expression for Parameter to set",defaultValue="The value of evaluating provided name against stack")
140:            public void setValue(String value) {
141:                this .value = value;
142:            }
143:
144:            /**
145:             * Tags can implement this to support nested param tags without the <tt>name</tt> attribute.
146:             * <p/>
147:             * The {@link Text TextTag} uses this approach. For unnamed parameters an example is given in the class
148:             * javadoc for {@link Param ParamTag}.
149:             */
150:            public interface UnnamedParametric {
151:
152:                /**
153:                 * Adds the given value as a parameter to the outer tag.
154:                 * @param value  the value
155:                 */
156:                public void addParameter(Object value);
157:            }
158:
159:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.