Skip to Main Content
Jakarta Struts Cookbook
book

Jakarta Struts Cookbook

by Bill Siggelkow
February 2005
Intermediate to advanced content levelIntermediate to advanced
528 pages
12h 53m
English
O'Reilly Media, Inc.
Content preview from Jakarta Struts Cookbook

3.13. Handling Date Input Fields

Problem

You want to allow a user to input a value for a calendar date.

Solution

First, only use String form fields to hold the input date values. If the user can manually type in the date, it helps if you provide graphical Calendar control, either client- or server-based, that can populate the date input fields automatically. When the date value is submitted, validate the input using the Struts Validator.

Here's a DynaActionForm, JSP page, and Action that demonstrate this approach. The DynaActionForm is declared with the following form-bean element:

<form-bean name="DateForm" 
           type="org.apache.struts.validator.DynaValidatorForm">
    <!-- Date 1 -->
    <form-property name="month" type="java.lang.String"/>
    <form-property name="day" type="java.lang.String"/>
    <form-property name="year" type="java.lang.String"/>
    <!-- Birth Date-->
    <form-property name="birthDateString" type="java.lang.String"/>
    <!-- Date 3 -->
    <form-property name="monthOpt" type="java.lang.String"/>
    <form-property name="dayOpt" type="java.lang.String"/>
    <form-property name="yearOpt" type="java.lang.String"/>
</form-bean>

The JSP page shown in Example 3-19 (date_test.jsp) renders fields for inputting data for these three variations of date formats. The first variation uses three numeric fields to accept the month, day, and year. The second variation accepts the date as a single value in mm/dd/yyyy format. This variation utilizes a JavaScript calendar that can be used to pick the value. The third variation ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Jakarta Struts

Programming Jakarta Struts

Chuck Cavaness
Beginning Spring Framework 2

Beginning Spring Framework 2

Bruce Snyder, Sing Li, Anne Horton, Thomas Van de Velde, Naveen Balani, Christian Dupuis
Java Cookbook

Java Cookbook

Ian F. Darwin
Struts 2 in Action

Struts 2 in Action

J. Scott Stanlick, Chad Michael Davis, Donald J. Brown

Publisher Resources

ISBN: 059600771XSupplemental ContentErrata Page