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