Using the Calendar component

Source: Internet
Author: User
Tags dateformat

This tutorial can be used to work with the following technologies and resources

JavaServer Faces component/Java EE platform 1.2 and Java EE 5* 1.1 and EE 1.4
Travel Database Not required

* To play the advantage of NetBeans IDE 6.0 's Java EE 5 performance, use an application server that is fully compatible with the Java EE 5 specification, such as the Sun Java System Application Server 9 (GlassFish project) 。

This tutorial is customized for the Sun Java application Server PE 9.0 Update Release 1. If you are using a different server, refer to the release notes and FAQs for known issues and workarounds. For more information about supported servers and Java EE platforms, see the release notes.

Select a calendar date

The JSF 1.2 calendar component used in this tutorial can be found in the basic categories of the palette. First, add a calendar to your project. The validation code is then added to verify that the date the user chooses falls within a default minimum and maximum calendar range.

Create a new Visual Web JSF application project, name it calendarexample, and select the Visual Web JavaServer Faces framework.

The page you designed is shown in the following illustration.

Figure 1: Calendar format Page Design

From the basic category of the palette, drag and drop a calendar component onto the page.

In the Properties window, set the following values:

Property Value
Id Startcalendar
Dateformatpatternhelp Mm/dd/yyyy
Label Start Date:
Required For True

Place a message component to the right of the calendar component. Hold down the Ctrl-shift key combination and drag a line from the message component to the Calendar component.

This action allows the message component to display an error message for the calendar component.

Place a static text component below the calendar component. Set ID property to Validationmsgstatictext.

Under the static text component, place a button component, enter Validate, and press ENTER. In the Properties window, set the ID property to Validatebutton.

Double-click the Validate button and add the following code to the Validatebutton action method:

code Example 1: code to validate calendar dates

public String validateButton_action() {
    validationMsgStaticText.setText(
        (String)DateFormat.getDateInstance(
        DateFormat.MEDIUM).format(startCalendar.getSelectedDate())
        + " is a valid date.");
    return null;
  }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.