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