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