View Javadoc

1   /*
2    * $Id: GenericUIBean.java 451544 2006-09-30 05:38:02Z mrdon $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts2.components;
19  
20  import javax.servlet.http.HttpServletRequest;
21  import javax.servlet.http.HttpServletResponse;
22  
23  import org.apache.struts2.util.ContainUtil;
24  
25  import com.opensymphony.xwork2.util.ValueStack;
26  
27  /***
28   * <!-- START SNIPPET: javadoc -->
29   * 
30   * Renders an custom UI widget using the specified templates. Additional objects can be passed in to the template
31   * using the param tags.<p/>
32   * 
33   * <b>Freemarker:</b><p/>
34   * Objects provided can be retrieve from within the template via $parameters._paramname_.<p/>
35   * 
36   * <b>Jsp:</b><p/>
37   * Objects provided can be retrieve from within the template via &lt;s:property value="%{parameters._paramname_}" /&gt;<p/>
38   *
39   *
40   * In the bottom JSP and Velocity samples, two parameters are being passed in to the component. From within the
41   * component, they can be accessed as:- <p/>
42   * 
43   * <b>Freemarker:</b><p/>
44   * $parameters.get('key1') and $parameters.get('key2') or $parameters.key1 and $parameters.key2<p/>
45   * 
46   * <b>Jsp:</b><p/>
47   * &lt;s:property value="%{parameters.key1}" /&gt; and &lt;s:property value="%{'parameters.key2'}" /&gt; or
48   * &lt;s:property value="%{parameters.get('key1')}" /&gt; and &lt;s:property value="%{parameters.get('key2')}" /&gt;<p/>
49   *
50   * Currently, your custom UI components can be written in Velocity, JSP, or Freemarker, and the correct rendering
51   * engine will be found based on file extension.<p/>
52   *
53   * <b>Remember:</b> the value params will always be resolved against the ValueStack so if you mean to pass a
54   * string literal to your component, make sure to wrap it in quotes i.e. value="'value1'" otherwise, the the value
55   * stack will search for an Object on the stack with a method of getValue1(). (now that i've written this, i'm not
56   * entirely sure this is the case. i should verify this manana)<p/>
57   * 
58   * <!-- END SNIPPET: javadoc -->
59   *
60   * <p/> <b>Examples</b>
61   *
62   * <pre>
63   * <!-- START SNIPPET: example -->
64   * JSP
65   *     &lt;s:component template="/my/custom/component.vm"/&gt;
66   *     
67   *       or
68   *
69   *     &lt;s:component template="/my/custom/component.vm"&gt;
70   *       &lt;s:param name="key1" value="value1"/&gt;
71   *       &lt;s:param name="key2" value="value2"/&gt;
72   *     &lt;/s:component&gt;
73   *
74   * Velocity
75   *     #s-component( "template=/my/custom/component.vm" )
76   *
77   *       or
78   *
79   *     #s-component( "template=/my/custom/component.vm" )
80   *       #s-param( "name=key1" "value=value1" )
81   *       #s-param( "name=key2" "value=value2" )
82   *     #end
83   *     
84   * Freemarker
85   *    &lt;@s..component template="/my/custom/component.ftl" />
86   *    
87   *      or
88   *      
89   *    &lt;@s..component template="/my/custom/component.ftl"&gt;
90   *       &lt;@s..param name="key1" value="%{'value1'}" /&gt;
91   *       &lt;@s..param name="key2" value="%{'value2'}" /&gt;
92   *    &lt;/@s..component&gt;
93   *     
94   * <!-- END SNIPPET: example -->
95   * </pre>
96   * 
97   * <p/>
98   * 
99   * <b>NOTE:</b>
100  * <!-- START SNIPPET: note -->
101  * 
102  * If Jsp is used as the template, the jsp template itself must lie within the 
103  * webapp itself and not the classpath. Unlike Freemarker or Velocity, JSP template
104  * could not be picked up from the classpath.
105  * 
106  * <!-- END SNIPPET: note -->
107  *
108  * @s.tag name="component" tld-body-content="JSP" tld-tag-class="org.apache.struts2.views.jsp.ui.ComponentTag"
109  * description="Render a custom ui widget"
110  */
111 public class GenericUIBean extends UIBean {
112     private final static String TEMPLATE = "empty";
113 
114     public GenericUIBean(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
115         super(stack, request, response);
116     }
117 
118     public boolean contains(Object obj1, Object obj2) {
119         return ContainUtil.contains(obj1, obj2);
120     }
121 
122     protected String getDefaultTemplate() {
123         return TEMPLATE;
124     }
125 }