Creating a Gregorian calendar

To create a calendar control involves creating a CalendarAdapter, a DateFormatAdapter, and a DateChooser. The example below shows you how to create a Gregorian calendar with date format in the English locale. When users click the calendar icon and choose a date from the calendar that opens, the selected date is used to populate the text field using the DateFormat.SHORT date format. The same concepts and steps can be applied to other types of calendars.
To create a Gregorian calendar in your JSP:
  1. Import the following packages and classes:
    <%@ page import="com.alphablox.blox.uimodel.core.*,
                     com.alphablox.blox.uimodel.*,
                     java.util.Calendar,
                     java.util.Locale"%>
  2. Import the Blox Tag Library:
    <%@ taglib uri="bloxtld" prefix="blox"%>
  3. Add a ContainerBlox to contain your DateChooser component:
    <blox:container id="dateChooserContainer">
  4. Get the BloxModel of the container:
    <%
       BloxModel model = dateChooserContainer.getBloxModel();
       ...
    %>
  5. Set the locale:
    Locale locale = Locale.US;
  6. Create the your CalendarAdapter:
    java.util.Calendar calendar = java.util.Calendar.getInstance( locale );
    ICalendar calendarAdapter = new CalendarAdapter( calendar );
  7. Create your DateFormatAdapter and apply the locale:
    java.text.DateFormat dateFormat = 
    java.text.DateFormat.getDateInstance( java.text.DateFormat.FULL, locale );
    IDateFormat dateFormatAdapter = new DateFormatAdapter( dateFormat );
  8. Create your DateChooser object with your CalendarAdapter, DateFormatAdapter, and locale using the DateChooser.getInstanceWithLocale() method:
    	<%
    DateChooser datechooser = 
    DateChooser.getInstanceWithLocale( calendarAdapter, dateFormatAdapter, locale );
    
    %>
  9. Add the DateChooser to the model of the container:
    <%
       ...
    	   model.add(datechooser1);
    %>
Here is the complete example:
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="com.alphablox.blox.uimodel.core.*,
                 com.alphablox.blox.uimodel.*,
                 java.util.Calendar,
                 java.util.Locale"%>
<%@ taglib uri="bloxtld" prefix="blox"%>

<html>
<head>
<blox:header/>
</head>
<body>
<blox:container id="dateChooserContainer">
<%
  BloxModel model = myContainer.getBloxModel();
  Locale locale = Locale.US;

  java.util.Calendar calendar = java.util.Calendar.getInstance( locale );
  ICalendar calendarAdapter = new CalendarAdapter( calendar );

  java.text.DateFormat dateFormat = 
java.text.DateFormat.getDateInstance( java.text.DateFormat.FULL, locale );
  IDateFormat dateFormatAdapter = new DateFormatAdapter( dateFormat );

  DateChooser datechooser = 
DateChooser.getInstanceWithLocale( calendarAdapter, dateFormatAdapter, locale );

  model.add( datechooser );%>
</blox:container>
</body>
</html>

You can easily modify the locale to create a non-English Gregorian calendar. There are other factory methods for creating a DateChooser depending on how you want to set the locale or the initially selected date. The Specifying a selected date when the calendar is launched example demonstrates another factory method for creating a DateChooser. It is possible to have one locale for your CalendarAdapter, another for your DateFormatAdapter, and yet another for your DateChooser. For example, you can have a Japanese calendar with DateFormat (the format to use when the selected date is displayed in the text box) in a different language.

You can use either Java's Calendar or the Calendar component in the International Components for Unicode (ICU) Java™ libraries. To support multiple locales, you should use ICU because of its better support for internalization. See Creating a Gregorian calendar using ICU for multi-locale support for more information.

For a live DateChooser example, see the "DateChooser Component" example in Blox Sampler, under the UI Extensibility section.

Related concepts
Creating a non-Gregorian calendar
Related tasks
Specifying a selected date when the calendar is launched