locale attribute! You can now specify the
desired locale as a tag attribute or as a pageContext attribute
named "locale"! See localizationThe CalendarTag is a Java JSP Taglib extension intended to be submitted to the Jakarta Apache Taglib Project which emits a calendar display for the current month in clean, CSS-formatted XHTML, suitable for display on a wide variety of web browsers, from Mozilla to WAP phones.
The calendar HTML on this page was generated by this tag (although the page that you're looking at is a static web page, not dynamic Java JSP).
The calendar can be used as a navigation aid for time-based data; see Navigation.
You may specify a locale in order to display the day and month names in various languages. However, this is a Gregorian calendar; different calendar systems such as Hebrew, Islamic, and Chinese calendars (to name a few) are not handled at this time. I am quite illiterate when it comes to alternate calendars, and therefore have no plan to implement alternate calendars. But if someone wants to help...
As a quick n' dirty example, this line of code in my HTML page:
<dt:calendar /> results in this output HTML (when run on
December 19, 2000, on a machine set up for the United States locale as
default):
<p> <pre class="calendar"> <span class="calMonth">December 2000</span> <span class="calDays"> Sun Mon Tue Wed Thu Fri Sat</span> <span class="calPrev"> 26 27 28 29 30 </span> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 <span class="calNow"> 19 </span> 20 21 22 23 24 25 26 27 28 29 30 31 <span class="calNext"> 1 2 3 4 5 6 </span> </pre> </p>
[ Sample Warfile ] [ Java source code ]
As I write this, (19 Dec 2000), the CalendarTag is two hours old, and is therefore not yet incorporated into the Jakarta Taglibs distribution. In the interest of getting the code out there, you can obtain the Java source code and the Sample Warfile from this web site. (NOTE: This web server does not set the document type correctly for the warfile. Tell your browser to save the link/target to disk!)
When/if this is approved for incorporation into the Taglibs project, it
will probably be a part of the datetime taglib, and you will be
able to get the CalendarTag by getting the taglib binary
distribution or the taglib source
distribution.
Until this tag is incorporated into the Jakarta Taglib distribution, you can try these steps to get the taglib working.
I suggest you get the Sample Warfile and deploy it in your JSP container in the manner specifed for war files. I've tested this with Tomcat-4.0 -- for this JSP server, you can simply:
webapps directoryhttp://myservername:8080/calendarTagOther JSP containers might have different methods, I don't know. For those of you not using Tomcat, here's some info that may or may not help...
A "war" file (web application archive) is just a Java JAR file that contains deployment descriptors, class libraries, and html files for a JSP 2.2 application. Given that it's just a JAR file, it's also just a ZIP file, so if you really need to take it apart, you can unzip it and look at the deployment descriptor files and the sample JSP file. The Java source for the file isn't included in the warfile; you can see the Java source code here.
Once you've got the sample webapp running, you know that you'll be able to add this tag to your own web applications:
datetime.jar file in
calendarTag/WEB-INF/lib to
yourWebApp/WEB-INF/libdatetime.tld file in
calendarTag/WEB-INF to yourWebApp/WEB-INFyourWebApp/WEB-INF/web.xml:
<taglib>
<taglib-uri>http://jakarta.apache.org/taglibs/datetime-1.0</taglib-uri>
<taglib-location>/WEB-INF/datetime.tld</taglib-location>
</taglib>
<%@ taglib uri="http://jakarta.apache.org/taglibs/datetime-1.0" prefix="dt" %>
<dt:calendar />
TODO: Discuss doing steps 4 and 5 with the new XML JSP file syntax
At the moment, (13 Jan 2001) there are FIVE optional parameters that you can set:
display |
Specify the month, in "MM/yyyy" format, that you want displayed,
e.g.:
<dt:calendar display="6/2000" />will display a calendar for June of the year 2000. |
today |
Specify the date, in "MM/dd/yyyy" format, that you would like
indicated as today's date, e.g.
<dt:calendar display="6/2000" today="5/29/2000" />will display a calendar for June of the year 2000, with May 29th highlighted as the current date. |
locale |
Specify the language code and country code for the locale that you
want, e.g.:
<dt:calendar locale="pt BR" />will display a calendar for the Brazillan Portuguese locale. The locale attribute can be delimited by any of the space '
', comma ',' , semi-colon ';', or dash '-' characters, so these are
all valid, too (I think): "pt-BR" "pt;BR" "pt, BR". Note that there is an optional third attribute which you can pass, which is a "locale variant" specifier, which might further refine a resource bundle depending on your Java environment. See the java.util.Locale documentation for more details. <dt:calendar locale="pt BR Traditional_POSIX" />Finally, note that the calendar tag will use the locale specifed in the pageContext using the findAttribute() call, which means that it will search for a Locale object named "locale" in page, request, session (if valid), and application scope(s) in order. So you can specify a Spanish (for example) display of the calendar tag by adding a pageContext directive in your JSP page: <% pageContext.setAttribute( "locale", java.util.Locale.SPAIN ); %> |
navigate |
The CalendarTag will form URLs for the days in the calendar based on
the date if either of the following are true:
|
urlFormat |
You may optionally set this attribute to a valid
SimpleDateFormat pattern string which will be used to
generate the date-based URLs. See navigation
for more information. |
My whole motivation for this taglib was to facilitate navigation on my XSLT-based RDF weblog (old static mirror here (shameless plug)). "A HREF" links work inside of PRE text for the browsers that I've tested, and appear to be the XHTML standard, so it's a question of how to specify these links to the tag. Here are the options currently implemented:
January 2001 Sun Mon Tue Wed Thu Fri Sat 31 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 1 2 3
The HTML for this tag looks like this:
<dt:calendar navigate="true" />
No tag body, no URL format specified, but navigation is enabled. Note that by default, the URLs which are generated are relative URLs. You can change this behavior by specifying an URL format.
January 2001 Sun Mon Tue Wed Thu Fri Sat 31 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 1 2 3
The HTML for this tag looks like this:
<dt:calendar navigate="true" urlFormat="'javascript:requestMethod(''processCalendar'','''MM/dd/yyyy''')'" />
Here's a calendar with particular days specified for navigation in the tag body, and a URL format for the navigation given for any dates that do not have a URL specified in the tag body.
January 2001 Sun Mon Tue Wed Thu Fri Sat 31 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 1 2 3
The HTML for this tag looks like this:
<dt:calendar urlFormat="'file:///C:/Documents%20and%20Settings/Administrator/My%20Documents/files/jot/'yyyy/MM/dd"> 01/04/2001 http://www.monkeymeat.com 01/13/2001 </dt:calendar>
See how the first date has a URL specified for it, but for the second tag, we form a URL by formatting the specified date with the urlFormat attribute via a java.text.SimpleDateFormat object.
Note that you do NOT have to set an URL format; the format is only used if you would like control over default URL generation. If you wish, you may specify each URL for each date in the BODY tag, and never need to use an URL format:
<dt:calendar> 01/04/2001 http://www.monkeymeat.com 01/13/2001 file:///C:/WINNT/System32/ 01/31/2001 http://www.w3.org </dt:calendar>
You can leave off specifying the URLs and the URL format, and you'll get the default relative URLs for just the days that are mentioned in the BODY:
<dt:calendar> 01/04/2001 01/13/2001 01/31/2001 </dt:calendar>
Finally, note that if you specify dates that are not in the current month,
you'll have to specify the month via the display property:
<dt:calendar display="06/2002"> 01/13/2002 06/09/2002 06/14/2002 </dt:calendar>
The first date specified in this example occurs before June 2002, so it does not affect the display of that date; it is ignored.
I think that the display date should be inferred from the dates that occur in the tag body; if all (or most of) the requested dates in the tag body are in the same month, then that month should be the one that's displayed. Hmm. Well, for now, that's NOT how it works; you have to specify a calendar month if you want to display a month different from the current date.
To wrap up, here are the two navigation attributes again:
<dt:calendar urlFormat="'javascript:requestMethod(''processCalendar'','''MM/dd/yyyy''')'" />
would result in markup like
<a href="javascript:requestMethod('processCalendar', '12/25/2000')">25</a>
This is totally easy from a programming standpoint, but it forces an awful mess upon you with respect to single-quote madness: a single single-quote is used to delimit literal text to appear in the URL -- that is, text not used to interpret the date formatting -- and double single-quotes are used to output a literal single-quote.
Well, if you're a JavaScript programmer, you're used to single-quote fun...
Another benefit of this approach is that the SimpleDateFormat strings are well-documented in the Java API documentation.
The BODY of the tag can contain text that is compatible with the
java.util.Properties serialization scheme:
<dt:calendar> 12/15/2000 http://www.monkeymeat.com 12/18/2000 http://www.foobar.com 12/31/2000 javascript:requestMethod( 'processCalendar', '12/31/2000' ) </dt:calendar>
Note that this method of mapping could be combined with the
urlPattern attribute to give you formatted links for just the
days that have entries:
<dt:calendar urlFormat="'http://www.grover.com/calServlet?date='yyyy/MM/dd"> 12/15/2000 12/18/2000 12/31/2000 </dt:calendar>
The HTML output by the CalendarTag is simple and XHTML-1.0 compliant. I rely upon CSS for my formatting. The output HTML is marked up with class attributes which permit CSS-compliant browsers to modify the appearance of the calendar elements, while minimizing the visual impact for non-conformant browsers.
In particular, this markup should look OK under text-only browsers such as Lynx or WAP phones.
In order to add formatting to your calendar, you need a CSS stylesheet. Here is the stylesheet that's used by this page:
<style type="text/css">
.calendar { background: #eeeeee; font: 11pt monospace; }
.calMonth { background: transparent; font: bold 12pt sans-serif; }
.calDays { background: #ccccff; }
.calPrev { background: #cccccc; }
.calNow { background: #ccffcc; }
.calNext { background: #cccccc; }
.calHoliday{background: #ffcccc; }
.sidebar { background: #cccccc; float: right; border: 3px solid black; }
.timestamp { font-weight: bold; margin-top: 0.3em; }
.example {
background: white;
margin-left: 2em; margin-right:2em;
border: 1pt solid black;
}
body { font: 12pt/13pt sans-serif; background: #eeeeee; }
h1, h2, h3, h4 { font-weight: bold }
h1 { font-size: 200% }
h2 { font-size: 150% }
h3 { font-size: 120% }
pre, code, dt { font-family: monospace }
strong{ font-weight: bold; }
</style>
Here is a description of the calendar CSS classes currently used:
Things I want to do, probably in order of importance to me:
The CalendarTag HTML output should conform to the XHTML 1.0 - Strict specification. I have verified compliance by using the W3C XHTML 1.0 validation service.
I have tested the HTML generated by the CalendarTag with the following platforms and browsers:
| Windows 2000 Professional (Athlon PC) | Internet Explorer 5.5,Mozilla M18, Mozilla 0.6, Mozilla 0.7, Netscape 4.76, XEmacs W3 |
| Linux Mandrake 7.1 (Athlon PC) | Mozilla M17, KDE Konqueror, Netscape 4.7 |
| Solaris 2.6 (Sun SPARC Ultra1) | Netscape 4.76, Lynx |
Other test platforms are welcome, in particular Macintosh platforms (iCAB!) and Opera. Last summer I was working on getting Mozilla compiled for my Solaris box, but at this point it's easier to wait for our IS department to upgrade to Solaris 2.8.
I chose to go with monospaced, "pre" tag text instead of an HTML for two reasons: 1) the pre tag renders correctly on more common text-based browsers and 2) the HTML code is much smaller.
The Visual Studio.NET beta 1 script debugger complains
about span anda hreftags occuring within the
enclosingpre tag on my Windows 2000 computer, but that the HTML
validates against the XHTML 1.0 Strict DTD. Perhaps the Visual Studio.NET beta
is using a different definition of HTML.
I am not certain exactly how XML would be used to specify the mapping between dates and URLs, but...
<dt:calendar linkMap="cal.xml" />
Like the option above, but the linkMap XML is given explicitly in the body of the tag. I like this option because I can generate the map XML from an XSLT tag embedded in this tag's body, e.g.
<dt:calendar>
<xsl:apply xsl="/xsl/rdf-to-linkmap.xsl">
<xsl:include page="/rss/slashdot.rdf"/>
</xsl:apply>
</dt:calendar>
-- is it accessible via a screen reader? This is important for people with vision difficulties, and also important to anyone developing an automated voice-jail system. I think that my "pre" text will read better on more HTML screen readers than a table represenation.
I have attempted to use Internet Explorer and the basic screen reader that ships with Windows 2000, but as I write this (January 2001), this combo doesn't pay attention to any of the features recommended by the W3C Accessibility commitee.
I will attempt to get XEmacs-W3 working with the Emacs reader; this seems to be a good platform for standards-compliant accessibility.