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:
2. You may add a header:
<%@ taglib uri="taglib.tld" prefix="cal" %> <cal:Calendar header="true" />
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>
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:
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:
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.
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.
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.
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.)
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 See also Coldtags suite - the largest collection of custom JSP tags.
|
Also in Coldtags:
|