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.views.annotations.StrutsTagAttribute;
28 import org.apache.struts2.StrutsConstants;
29
30 import com.opensymphony.xwork2.inject.Inject;
31 import com.opensymphony.xwork2.util.ValueStack;
32
33 /***
34 * <!-- START SNIPPET: javadoc -->
35 *
36 * Renders parts of the HEAD section for an HTML file. This is useful as some themes require certain CSS and JavaScript
37 * includes.<p/>
38 *
39 * If, for example, your page has ajax components integrated, without having the default theme set to ajax, you might
40 * want to use the head tag with <b>theme="ajax"</b> so that the typical ajax header setup will be included in the
41 * page.<p/>
42 *
43 * The tag also includes the option to set a custom datepicker theme if needed. See calendarcss parameter for
44 * description for details.<p/>
45 *
46 * If you use the ajax theme you can turn a debug flag on by setting the debug parameter to <tt>true</tt>.
47 *
48 * <!-- END SNIPPET: javadoc -->
49 *
50 * <p/> <b>Examples</b>
51 *
52 * <pre>
53 * <!-- START SNIPPET: example1 -->
54 * <head>
55 * <title>My page</title>
56 * <s:head/>
57 * </head>
58 * <!-- END SNIPPET: example1 -->
59 * </pre>
60 *
61 * <pre>
62 * <!-- START SNIPPET: example2 -->
63 * <head>
64 * <title>My page</title>
65 * <s:head theme="ajax" calendarcss="calendar-green"/>
66 * </head>
67 * <!-- END SNIPPET: example2 -->
68 * </pre>
69 *
70 * <pre>
71 * <!-- START SNIPPET: example3 -->
72 * <head>
73 * <title>My page</title>
74 * <s:head theme="ajax" debug="true"/>
75 * </head>
76 * <!-- END SNIPPET: example3 -->
77 * </pre>
78 *
79 */
80 @StrutsTag(name="head", tldBodyContent="empty", tldTagClass="org.apache.struts2.views.jsp.ui.HeadTag",
81 description="Render a chunk of HEAD for your HTML file")
82 public class Head extends UIBean {
83 public static final String TEMPLATE = "head";
84
85 private String calendarcss = "calendar-blue.css";
86 private boolean debug;
87 private String encoding;
88
89 public Head(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
90 super(stack, request, response);
91 }
92
93 protected String getDefaultTemplate() {
94 return TEMPLATE;
95 }
96
97 @Inject(StrutsConstants.STRUTS_I18N_ENCODING)
98 public void setEncoding(String encoding) {
99 this.encoding = encoding;
100 }
101
102 public void evaluateParams() {
103 super.evaluateParams();
104
105 if (calendarcss != null) {
106 String css = findString(calendarcss);
107 if (css != null && css.trim().length() > 0) {
108 if (css.lastIndexOf(".css") < 0) {
109 addParameter("calendarcss", css + ".css");
110 } else {
111 addParameter("calendarcss", css);
112 }
113 }
114 }
115
116 addParameter("encoding", encoding);
117 addParameter("debug", Boolean.valueOf(debug).toString());
118 }
119
120 public String getCalendarcss() {
121 return calendarcss;
122 }
123
124 @StrutsTagAttribute(description="The jscalendar css theme to use", defaultValue="calendar-blue.css")
125 public void setCalendarcss(String calendarcss) {
126
127 this.calendarcss = calendarcss;
128 }
129
130 public boolean isDebug() {
131 return debug;
132 }
133
134 @StrutsTagAttribute(description="Set to true to enable debugging mode for AJAX themes")
135 public void setDebug(boolean debug) {
136 this.debug = debug;
137 }
138
139
140 }