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;
}