001: package com.opensymphony.webwork.components;
002:
003: import com.opensymphony.xwork.ActionContext;
004: import com.opensymphony.xwork.util.OgnlValueStack;
005:
006: import javax.servlet.http.HttpServletRequest;
007: import javax.servlet.http.HttpServletResponse;
008: import java.util.Locale;
009:
010: /**
011: * <!-- START SNIPPET: javadoc -->
012: *
013: * Renders datepicker element.</p>
014: *
015: * Implementation was changed in WebWork 2.2 to use <a href="http://www.dynarch.com/projects/calendar/">jscalendar</a>
016: * instead of non locale aware tigracalendar. Check locale and format settings if you used the old widget in your
017: * applications. Be sure to include proper stylesheet as described below if you don't want the calender widget to look
018: * transparent.</p>
019: *
020: * <b>Important:</b> Be sure to set the id attributs if not used within a <ww:form /> tag, as it takes care of
021: * setting the id for you, being required to copy selected date to text input element.</p>
022: *
023: * Following a reference for the format parameter (copied from jscalendar documentation):
024: * <table border=0><tr><td valign=top ></td></tr>
025: * <tr><td valign=top ><tt>%a</tt> </td><td valign=top >abbreviated weekday name </td></tr>
026: * <tr><td valign=top ><tt>%A</tt> </td><td valign=top >full weekday name </td></tr>
027: * <tr><td valign=top ><tt>%b</tt> </td><td valign=top >abbreviated month name </td></tr>
028: * <tr><td valign=top ><tt>%B</tt> </td><td valign=top >full month name </td></tr>
029: * <tr><td valign=top ><tt>%C</tt> </td><td valign=top >century number </td></tr>
030: * <tr><td valign=top ><tt>%d</tt> </td><td valign=top >the day of the month ( 00 .. 31 ) </td></tr>
031: * <tr><td valign=top ><tt>%e</tt> </td><td valign=top >the day of the month ( 0 .. 31 ) </td></tr>
032: * <tr><td valign=top ><tt>%H</tt> </td><td valign=top >hour ( 00 .. 23 ) </td></tr>
033: * <tr><td valign=top ><tt>%I</tt> </td><td valign=top >hour ( 01 .. 12 ) </td></tr>
034: * <tr><td valign=top ><tt>%j</tt> </td><td valign=top >day of the year ( 000 .. 366 ) </td></tr>
035: * <tr><td valign=top ><tt>%k</tt> </td><td valign=top >hour ( 0 .. 23 ) </td></tr>
036: * <tr><td valign=top ><tt>%l</tt> </td><td valign=top >hour ( 1 .. 12 ) </td></tr>
037: * <tr><td valign=top ><tt>%m</tt> </td><td valign=top >month ( 01 .. 12 ) </td></tr>
038: * <tr><td valign=top ><tt>%M</tt> </td><td valign=top >minute ( 00 .. 59 ) </td></tr>
039: * <tr><td valign=top ><tt>%n</tt> </td><td valign=top >a newline character </td></tr>
040: * <tr><td valign=top ><tt>%p</tt> </td><td valign=top >``PM'' or ``AM'' </td></tr>
041: * <tr><td valign=top ><tt>%P</tt> </td><td valign=top >``pm'' or ``am'' </td></tr>
042: * <tr><td valign=top ><tt>%S</tt> </td><td valign=top >second ( 00 .. 59 ) </td></tr>
043: * <tr><td valign=top ><tt>%s</tt> </td><td valign=top >number of seconds since Epoch (since Jan 01 1970 00:00:00 UTC) </td></tr>
044: * <tr><td valign=top ><tt>%t</tt> </td><td valign=top >a tab character </td></tr>
045: * <tr><td valign=top ><tt>%U, %W, %V</tt> </td><td valign=top >the week number</td></tr>
046: * <tr><td valign=top ><tt>%u</tt> </td><td valign=top >the day of the week ( 1 .. 7, 1 = MON )</td></tr>
047: * <tr><td valign=top ><tt>%w</tt> </td><td valign=top >the day of the week ( 0 .. 6, 0 = SUN )</td></tr>
048: * <tr><td valign=top ><tt>%y</tt> </td><td valign=top >year without the century ( 00 .. 99 )</td></tr>
049: * <tr><td valign=top ><tt>%Y</tt> </td><td valign=top >year including the century ( ex. 1979 )</td></tr>
050: * <tr><td valign=top ><tt>%%</tt> </td><td valign=top >a literal <tt>%</tt> character
051: * </td></tr></table><p>
052: *
053: * <!-- END SNIPPET: javadoc -->
054: *
055: * <p/> <b>Examples</b>
056: *
057: * <pre>
058: * <!-- START SNIPPET: expl1 -->
059: * Date in application's locale format:
060: * <ww:datepicker name="order.date" id="order.date" />
061: * Date in german locale, with german texts:
062: * <ww:datepicker name="delivery.date" id="delivery.date" template="datepicker_js.ftl" language="de" />
063: * Date in german locale, with german texts and custom date format, including time:
064: * <ww:datepicker name="invoice.date" id="invoice.date" template="datepicker_js.ftl" language="de" format="%d. %b &Y %H:%M" showstime="true" />
065: * <!-- END SNIPPET: expl1 -->
066: * </pre>
067: * <p/>
068: *
069: * <!-- START SNIPPET: expldesc2 -->
070: *
071: * If you use this jscalendar based datepicker widget, you might want to use one of the standard stylesheets provided
072: * with jscalendar (all distribution stylesheets are included in webwork jar). The easiest way to do so is to place the
073: * <ww:head/> tag in the head of your html page, as it takes care of including calendar css.
074: * Otherwise, to manually activate the calendar-blue style, include the following in your stylesheet definition:
075: *
076: * <!-- END SNIPPET: expldesc2 -->
077: * <pre>
078: * <!-- START SNIPPET: expl2 -->
079: * <link href="<ww:url value="/webwork/jscalendar/calendar-blue.css" />" rel="stylesheet" type="text/css" media="all"/>
080: * <!-- END SNIPPET: expl2 -->
081: * </pre>
082: *
083: * @author Patrick Lightbody
084: * @author Rene Gielen
085: * @version $Revision: 2541 $
086: * @ww.tag name="datepicker" tld-body-content="JSP" tld-tag-class="com.opensymphony.webwork.views.jsp.ui.DatePickerTag"
087: * description="Render datepicker"
088: * @since 2.2
089: */
090: public class DatePicker extends TextField {
091:
092: final public static String TEMPLATE = "datepicker";
093:
094: protected String language;
095: protected String format;
096: protected String showstime;
097: protected String singleclick;
098:
099: public DatePicker(OgnlValueStack stack, HttpServletRequest request,
100: HttpServletResponse response) {
101: super (stack, request, response);
102: }
103:
104: protected String getDefaultTemplate() {
105: return TEMPLATE;
106: }
107:
108: public void evaluateParams() {
109: super .evaluateParams();
110:
111: if (language != null) {
112: addParameter("language", findString(language));
113: } else {
114: final Locale locale = (Locale) getStack().getContext().get(
115: ActionContext.LOCALE);
116: if (locale != null) {
117: addParameter("language", locale.getLanguage());
118: } else {
119: addParameter("language", Locale.getDefault()
120: .getLanguage());
121: }
122:
123: }
124:
125: if (format != null) {
126: addParameter("format", findString(format));
127: }
128:
129: if (showstime != null) {
130: addParameter("showstime", findString(showstime));
131: }
132:
133: if (singleclick != null) {
134: addParameter("singleclick", findString(singleclick));
135: }
136:
137: }
138:
139: /**
140: * The language to use for the widget texts and localization presets.
141: * @ww.tagattribute required="false" type="String" default="The language of the current Locale"
142: */
143: public void setLanguage(String language) {
144: this .language = language;
145: }
146:
147: /**
148: * The format to use for date field.
149: * @ww.tagattribute required="false" type="String" default="Dateformat specified by language preset (%Y/%m/%d for en)"
150: */
151: public void setFormat(String format) {
152: this .format = format;
153: }
154:
155: /**
156: * Whether time selector is to be shown. Valid values are "true", "false", "24" and "12".
157: * @ww.tagattribute required="false" type="String" default="false"
158: */
159: public void setShowstime(String showstime) {
160: this .showstime = showstime;
161: }
162:
163: /**
164: * Whether to use selected value after single or double click.
165: * @ww.tagattribute required="false" type="Boolean" default="true"
166: */
167: public void setSingleclick(String singleclick) {
168: this.singleclick = singleclick;
169: }
170:
171: }
|