Calendar taglib ver. 3.8


    Custom JSP tags. Lets you present calendar control in your applications. .NET developers know the similar web form in .NET framework. With this taglib the same functionality is available for JSP developers too. For example:

1. Simple form:
 


<%@ taglib uri="taglib.tld" prefix="cal" %>

<cal:Calendar />

and you will see some like this:

 Sun Mon Tue Wed Thu Fri Sat
  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      

2. You may add a header:
 


<%@ taglib uri="taglib.tld" prefix="cal" %>

<cal:Calendar header="true" />


 Oct 2001 
 
 Sun Mon Tue Wed Thu Fri Sat
  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      

Tag setHeaderFormat lets you customize header. For example:
 


<cal:setHeaderFormat>MMMM</cal:setHeaderFormat>

will print a full name of month in the header.

3. Predefined variables for dates.

Within tag's body you can use predefined variables (types are java.lang.Integer). currYear is a current (not tag's!) year, currMonth is a current month (interval is 1-12), currDate is a current day and currDay is a day of week (interval is 1-7), nextMonth is a next (for this tag) month, prevMonth is a previous (for this tag) month, nextYear is currYear+1 if nextMonth == 1 and currYear otherwise, prevYear is currYear-1 if prevMonth == 12 and currYear otherwise.

4. You may add a hyperlink for any date (all dates):
 


<%@ taglib uri="taglib.tld" prefix="cal" %>

<cal:Calendar>
  <cal:setLink day="5">http://www.servletsuite.com</cal:setLink>
  <cal:setLink day="15">http://www.servletsuite.com/jsp.htm</cal:setLink>
</cal:Calendar>


 Sun Mon Tue Wed Thu Fri Sat
  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      

or let us see a link for the current date:
 


<cal:setLink day="<%=currDate%>">http://www.servletsuite.com</cal:setLink>

When you describe any hyperlink or body for date you may use meta symbols $d (will be replaced by the selected day), $m (will be replaced by the selected month) and $y (will be replaced by the selected year). For example this tag sets hyperlinks for all days and for the each request day will be passed as a query parameter:
 

<cal:setLink>http://www.servletsuite.com?$d</cal:setLink>

You may define HTML settings for calendar's elements: describe CSS class or style. Here is a bit more complex example with various attributes:
 


<style>
.test
{
color:white;
background:black;
}
</style>

<cal:Calendar month="11" locale="<%=java.util.Locale.GERMANY%>" header="true">
   <cal:setTitleStyle>font-size:10pt; color:#FF0000</cal:setTitleStyle>
   <cal:setHeaderStyle>color:#0000FF; text-decoration:none</cal:setHeaderStyle>
   <cal:setLink day="5">http://www.servletsuite.com</cal:setLink>
   <cal:setLink day="15">http://www.servletsuite.com/jsp.htm?$d</cal:setLink>
   <cal:setDateClass day="10">test</cal:setDateClass>
   <cal:setTarget>_blank</cal:setTarget>

   <cal:setNextMonth>http://www.servletsuite.com?$m</cal:setNextMonth>
   <cal:setPrevMonth>http://www.servletsuite.com?$m</cal:setPrevMonth>
</cal:Calendar>

and you will see the following calendar:

<<Nov 2001>>
 
 Mo  Di  Mi  Do  Fr  Sa  So 
       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     

Also you may set your own JSP code describes how to output (display) some day (all days). By default it is just a day (with possible hyperlink). Body tag setDateBody lets you customize this output. Within this tag you may use predefined variables: D (type is java.lang.Integer, value is day for this tag), M (type is java.lang.Integer, value is a month for calendar in 1-12 interval), Y (type is java.lang.Integer, value is a year for calendar) and LINK (type is java.lang.String, value is a hyperlink for day in tag). For example, let us output a table for day 15 in the last example:
 


...
<cal:setDateBody day="15">
  <table border=1 width=25 height=25>
   <tr><td align=center><%=LINK%></td></tr>
  </table>
</cal:setDateBody>
...

and you will get the following:

<<Nov 2001>>
 
 Mo  Di  Mi  Do  Fr  Sa  So 
       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     

You can use your calendar just for date selection also. You may insert selected date into some field on your page. For example you may use Calendar in javascript pop-up window and deploy setField tag instead of setLink. Tag setField describes some field in your HTML form for selected date. Let us see an example:
 


<form name=form1>
<input type="text" name="dt">
<input type="button" value="Set Date" onClick="window.open('calendar.jsp','date','width=400,height=200, toolbar=no, location=no,menubar=no');">
</form>

So our data field is form1.dt (form name is form1, field name is dt and calendar uses a separate window). In file calendar.jsp we will use Calendar tag:
 


<cal:Calendar>
  <cal:setField>form1.dt</cal:setField>
</cal:Calendar>

Let us try this in action:

Tag setField lets you also define a format for selected date and describe location for your form.

Tags are:

Calendar

Displays calendar. Parameters are:

1) month Optional parameter. Possible values are 1-12. By default is current month.
2) year Optional parameter. Sets year. By default is current year.
3) locale Optional parameter. Describes a locale. How to display days (what is a first day: Monday or Sunday) depends on the locale. By default tag will use locale from browser's preferences.
4) header Optional parameter. Possible values are true or false. Enables/disables header. Default value is false.
5) style Optional parameter. Describes your own CSS style for calendar.
6) className Optional parameter. Describes your own CSS class for calendar.

any tag described below is used in the context of Calendar tag:

setNextMonth

Body tag. Body describes a hyperlink for the 'next month' view (could be a part of the header). By default (if tag's body is empty) this hyperlink will be the current URL and the following query string: month=NEXT_MONTH&year=YEAR_VALUE where NEXT_MONTH is a value for the next month and YEAR_VALUE is a current (or next) year. Parameters are: none

setNextMonthBody

Body tag. Body describes a body for the 'next month' hyperlink. By default it is >>.

setNextMonthClass

Body tag. Body describes a css class for the 'next month' data.

setNextMonthStyle

Body tag. Body describes a css style for the 'next month' data.

setPrevMonth

Body tag. Body describes a hyperlink for the 'previous month' view (could be a part of the header). By default (if tag's body is empty) this hyperlink will be the current URL and the following query string: month=PREV_MONTH&year=YEAR_VALUE where PREV_MONTH is a value for the previous month and YEAR_VALUE is a current (or previous) year. Parameters are: none

setPrevMonthBody

Body tag. Body describes a body for the 'prev month' hyperlink. By default it is <<.

setPrevMonthClass

Body tag. Body describes a css class for the 'prev month' data.

setPrevMonthStyle

Body tag. Body describes a css style for the 'prev month' data.

setLink

Body tag. Body describes a hyperlink for the particular day (all days). Parameters are:

1) day Optional parameter. Describes some day. Possible values are 1-31. By default link will be assigned for all days.
2) cond Optional parameter. Describes a boolean value tag's behavior depends on. Default value is true (set link)

setTarget

Body tag. Body describes a target frame for hyperlink (hyperlinks). Parameters are:

1) day Optional parameter. Describes some day. Possible values are 1-31. By default target frame will be assigned for all hyperlinks.

setField

Body tag. Body describes a field in some form that will be initialized by the selected date. Parameters are:

1) day Optional parameter. Describes some day. Possible values are 1-31. By default this will be assigned for all days.
2) format Optional parameter. Describes a format for returned date. E.g.: yyyy-MM-dd. By default tag will use MM/dd/yyyy or dd/MM/yyyy format depends on locale.
3) window Optional parameter. Possible values are true or false. You have to set this value to false if your form and calendar both are on the same page. Default value is true (calendar uses a separate window).
4) multiple Optional parameter. Possible values are true or false. If this value is true selected value will be concatenated to the current filed value. Also tag does not close window in this case. So you will be able to select multiple dates and accumulate them as a space separated list in the given field. Default value is false.

setHeaderClass

Body tag. Body describes a CSS class name for header. Parameters are: none

setHeaderStyle

Body tag. Body describes a CSS style for header. Parameters are: none

setHeaderFormat

Body tag. Body describes a format for header. By default it is MMM yyyy. Parameters are: none

setTitleClass

Body tag. Body describes a CSS class name for title (titles). Parameters are:

1) day Optional parameter. Describes some day. Possible values are 1-7. By default this will be assigned for all days.

setTitleStyle

Body tag. Body describes a CSS style for title (titles). Parameters are:

1) day Optional parameter. Describes some day. Possible values are 1-7. By default this will be assigned for all days.

setTitleFormat

Body tag. Body describes a format for title (titles). Parameters are:

1) day Optional parameter. Describes some day. Possible values are 1-7. By default this format will be assigned for all days. By default Calendar uses format EEE for titles (e.g. Mon, Tue, Wed etc.)
2) length Optional parameter. Describes a maximal length for day's title. By default is undefined (unrestricted).

setDateClass

Body tag. Body describes a CSS class name for some day (all days). Parameters are:

1) day Optional parameter. Describes some day. Possible values are 1-31. By default this will be assigned for all days.

setDateStyle

Body tag. Body describes a CSS style for some day (all days). Parameters are:

1) day Optional parameter. Describes some day. Possible values are 1-31. By default this will be assigned for all days.

setLinkClass

Body tag. Body describes a CSS class name for day's hyperlink (for all days). Parameters are:

1) day Optional parameter. Describes some day. Possible values are 1-31. By default this will be assigned for all days.

setLinkStyle

Body tag. Body describes a CSS style for day's hyperlink (for all days). Parameters are:

1) day Optional parameter. Describes some day. Possible values are 1-31. By default this will be assigned for all days.

setSundayClass

Body tag. Body describes a CSS class name for Sunday (for all days). Parameters are:

1) prevail Optional parameter. Possible values are true or false. If this value is false than day's settings will prevail over the specified settings. Default value is true (this value will prevail).

setSundayStyle

Body tag. Body describes a CSS style for Sunday (for all days). Parameters are:

1) prevail Optional parameter. Possible values are true or false. If this value is false than day's settings will prevail over the specified settings. Default value is true (this value will prevail).

setSaturdayClass

Body tag. Body describes a CSS class name for Saturday (for all days). Parameters are:

1) prevail Optional parameter. Possible values are true or false. If this value is false than day's settings will prevail over the specified settings. Default value is true (this value will prevail).

setSaturdayStyle

Body tag. Body describes a CSS style for Saturday (for all days). Parameters are:

1) prevail Optional parameter. Possible values are true or false. If this value is false than day's settings will prevail over the specified settings. Default value is true (this value will prevail).

setDateBody

Body tag. Body describes your own JSP code for some day (all days). Parameters are:

1) day Optional parameter. Describes some day. Possible values are 1-31. By default this will be assigned for all days.

Note: the evaluation version displays data for the current month only!

For downloading:

Evaluation version: caltag.jar    Description: taglib.tld

Buy it here: Buy this taglib

 © Coldbeans      Comments?

See also Coldtags suite - the largest collection of custom JSP tags.

Also in Coldtags: