javawebparts.taglib.uiwidgets
Class CalendarTag

java.lang.Object
  |
  +--javax.servlet.jsp.tagext.TagSupport
        |
        +--javax.servlet.jsp.tagext.BodyTagSupport
              |
              +--javawebparts.taglib.uiwidgets.CalendarTag
All Implemented Interfaces:
javax.servlet.jsp.tagext.BodyTag, javax.servlet.jsp.tagext.IterationTag, java.io.Serializable, javax.servlet.jsp.tagext.Tag

public class CalendarTag
extends javax.servlet.jsp.tagext.BodyTagSupport

This class is a custom tag that renders the Calendar UI widget.

The attribute this tag takes are:

  • maxYear - The end of the range of years to display in the year dropdown. Required: No. Default: The current year.
  • styleOverrides - This is a comma-separated list of the style selectors you will supply yourself. If this attribute is not present, or is an empty string, or is the value "none", then all the built-in style selectors will be rendered on the page. In other words, there will be no way for you to style the calendar yourself. You can override any subset of the style selectors, or all of them. To override all of them, set this attribute to "all". To override a subset of them, set this attribute to a comma-separated list of the selectors you will override, taken from the following list:

    - cssCalendarOuter - This styles the outer border.
    - cssCalendarMain - This styles the main background portion of the calendar.
    - cssCalendarButton - This styles the two buttons.
    - cssCalendarDropdown - This styles the two dropdowns.
    - cssCalendarDay - This styles days of the week (not weekends).
    - cssCalendarWeekend - This styles weekend days (not weekdays).
    - cssCalendarHover - This styles any day of the week when the mouse is hovering over it.

    Because when you override a selector you must supply the entire selector, i.e., you cannot override just the background-color attribute of the buttons, you must instead supply the entire cssCalendarButton selector, here are the default styles which you should probably modify and/or build off of:

    .cssCalendarOuter { background-color:#efefef; color:#000000; border:1px solid #000000; font-family:arial; font-size:11pt; font-weight:bold; font-style:normal; font-variant:normal; text-decoration:none; }
    .cssCalendarMain { position:absolute; width:auto; height:auto; left:0px; top:0px; z-index:1000; display:none; color:#000000; font-family:arial; font-size:11pt; font-weight:bold; font-style:normal; font-variant:normal; text-decoration:none; cursor:default; }
    .cssCalendarButton { color:#000000; font-family:arial; font-size:11pt; font-weight:bold; font-style:normal; font-variant:normal; text-decoration:none; cursor:pointer; }
    .cssCalendarDropdown { color:#000000; font-family:arial; font-size:11pt; font-weight:bold; font-style:normal; font-variant:normal; text-decoration:none; cursor:pointer; }
    .cssCalendarDay { color:#ffffff; background-color:#990033; font-family:arial; font-size:11pt; font-weight:bold; font-style:normal; font-variant:normal; text-decoration:none; cursor:pointer; width:20px; }
    .cssCalendarWeekend { color:#c0c0b0; background-color:#990033; font-family:arial; font-size:11pt; font-weight:bold; font-style:normal; font-variant:normal; text-decoration:none; cursor:pointer; width:20px; }
    .cssCalendarHover { color:#ffffff; background-color:#ccb433; font-family:arial; font-size:11pt; font-weight:bold; font-style:normal; font-variant:normal; text-decoration:none; width:20px; cursor:pointer; }
    Required: No. Default: Same as "none".


    To use the Calendar widget, perform the following steps:

    1. Place a <uiwidgets:calendar/> tag on the page. You only need to place one, regardless of how many calendar you actually will have, and you should be able to place it anywhere on the page. Here is an example taken from the JWP sample app:

      <uiwidgets:calendar minYear="1990" maxYear="2010" styleOverrides="cssCalendarButton,cssCalendarDropdown" />

      This will make the calendar have years listed from 1990 through 2010 (inclusive) and the cssCalendarButton and cssCalendarDropdown style selectors will NOT be rendered, so you must provide them.
    2. Add the following Javascript event handler to whatever element will cause the calendar to be shown:

      onClick="showCalendar(calendarForm1.myDate1);"

      The parameter you pass to this method is the form.element that will receive the date. This should be a form text input element. This lets you give the user the opportunity to still manually enter a date, or you can disable the textbox to only allow input via the calendar.

      The date returned is always in the form MM/DD/YYYY. Single-digit values are zero=padded out to two places (i.e., you will get 01/05/2006 instead of 1/5/2006).
    3. If you have <select> elements on your page, for each, call the JWPCalendarAddDropdown() function like so:

      JWPCalendarAddDropdown("AjaxPartsTestForm.selbox2"); JWPCalendarAddDropdown("testSelect");

      Note that these calls MUST execute AFTER the page loads, or after the widget tag appears on the page! So, either call some function onLoad to execute these statements, or make sure the tag comes before them physically on the page.

      The calendar will first try and access the dropdown using DOM ID, and if it is not found it will then try and eval the value you passed to this function. If the element is part of a form, you should prefix the element name with the form name, as shown above. If it isn't part of a form, it should be found by the eval branch, but you would be better off to give it a real ID to find to avoid any cross-browser problems.
    4. OPTIONAL: If you are overridding styles, make sure they are on the page either literally or imported.

    Author:
    Frank W. Zammetti.
    See Also:
    Serialized Form

    Field Summary
    private static org.apache.commons.logging.Log log
              Log instance.
    private  java.lang.String maxYear
              The maximum year to show in the dropdown.
    private  java.lang.String minYear
              The minimum year to show in the dropdown.
    private  java.lang.String styleOverrides
              The style selectors that will be overridden.
     
    Fields inherited from class javax.servlet.jsp.tagext.BodyTagSupport
    bodyContent
     
    Fields inherited from class javax.servlet.jsp.tagext.TagSupport
    id, pageContext
     
    Fields inherited from interface javax.servlet.jsp.tagext.BodyTag
    EVAL_BODY_BUFFERED, EVAL_BODY_TAG
     
    Fields inherited from interface javax.servlet.jsp.tagext.IterationTag
    EVAL_BODY_AGAIN
     
    Fields inherited from interface javax.servlet.jsp.tagext.Tag
    EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
     
    Constructor Summary
    CalendarTag()
               
     
    Method Summary
     int doStartTag()
              Render widget code.
    private  void renderMarkup(java.lang.StringBuffer sb, java.lang.String inMinYear, java.lang.String inMaxYear)
              Renders the makrup for the calendar.
    private  void renderScript(java.lang.StringBuffer sb)
              Renders the script block for the calendar.
    private  void renderStyles(java.lang.StringBuffer sb, boolean anyStyleOverrides, java.util.HashMap overriddenStyles)
              Renders the style block for the calendar.
     void setMaxYear(java.lang.String inMaxYear)
              Set the maxYear field.
     void setMinYear(java.lang.String inMinYear)
              Set the minYear field.
     void setStyleOverrides(java.lang.String inStyleOverrides)
              Set the styleOverrides field.
     
    Methods inherited from class javax.servlet.jsp.tagext.BodyTagSupport
    doAfterBody, doEndTag, doInitBody, getBodyContent, getPreviousOut, release, setBodyContent
     
    Methods inherited from class javax.servlet.jsp.tagext.TagSupport
    findAncestorWithClass, getId, getParent, getValue, getValues, removeValue, setId, setPageContext, setParent, setValue
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     
    Methods inherited from interface javax.servlet.jsp.tagext.Tag
    getParent, setPageContext, setParent
     

    Field Detail

    log

    private static org.apache.commons.logging.Log log
    Log instance.


    minYear

    private java.lang.String minYear
    The minimum year to show in the dropdown.


    maxYear

    private java.lang.String maxYear
    The maximum year to show in the dropdown.


    styleOverrides

    private java.lang.String styleOverrides
    The style selectors that will be overridden.

    Constructor Detail

    CalendarTag

    public CalendarTag()
    Method Detail

    setMinYear

    public void setMinYear(java.lang.String inMinYear)
    Set the minYear field.

    Parameters:
    inMinYear - The value of the minYear tag attribute.

    setMaxYear

    public void setMaxYear(java.lang.String inMaxYear)
    Set the maxYear field.

    Parameters:
    inMaxYear - The value of the maxYear tag attribute.

    setStyleOverrides

    public void setStyleOverrides(java.lang.String inStyleOverrides)
    Set the styleOverrides field.

    Parameters:
    inStyleOverrides - The value of the styleOverrides tag attribute.

    doStartTag

    public int doStartTag()
                   throws javax.servlet.jsp.JspException
    Render widget code.

    Specified by:
    doStartTag in interface javax.servlet.jsp.tagext.Tag
    Overrides:
    doStartTag in class javax.servlet.jsp.tagext.BodyTagSupport
    Returns:
    Return code.
    Throws:
    javax.servlet.jsp.JspException - If anything goes wrong

    renderStyles

    private void renderStyles(java.lang.StringBuffer sb,
                              boolean anyStyleOverrides,
                              java.util.HashMap overriddenStyles)
    Renders the style block for the calendar.

    Parameters:
    sb - StringBuffer the output is being built up in.
    anyStyleOverrides - True if the developer wants to override any of the styles, false if not.
    overriddenStyles - A Map of styles the developer wants to override.

    renderScript

    private void renderScript(java.lang.StringBuffer sb)
    Renders the script block for the calendar.

    Parameters:
    sb - StringBuffer the output is being built up in.

    renderMarkup

    private void renderMarkup(java.lang.StringBuffer sb,
                              java.lang.String inMinYear,
                              java.lang.String inMaxYear)
    Renders the makrup for the calendar.

    Parameters:
    sb - StringBuffer the output is being built up in.
    inMinYear - The start of the range for the year dropdown.
    inMaxYear - The end of the range for the year dropdown.


    Copyright © 2005 Frank W. Zammetti