1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 <s:property value="%{parameters._paramname_}" /><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 * <s:property value="%{parameters.key1}" /> and <s:property value="%{'parameters.key2'}" /> or
48 * <s:property value="%{parameters.get('key1')}" /> and <s:property value="%{parameters.get('key2')}" /><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 * <s:component template="/my/custom/component.vm"/>
66 *
67 * or
68 *
69 * <s:component template="/my/custom/component.vm">
70 * <s:param name="key1" value="value1"/>
71 * <s:param name="key2" value="value2"/>
72 * </s:component>
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 * <@s..component template="/my/custom/component.ftl" />
86 *
87 * or
88 *
89 * <@s..component template="/my/custom/component.ftl">
90 * <@s..param name="key1" value="%{'value1'}" />
91 * <@s..param name="key2" value="%{'value2'}" />
92 * </@s..component>
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 }