Setting a date format, Setting a date format 88 – Apple WebObjects 3.5 User Manual

Page 88

Advertising
background image

Chapter 3

Creating a WebObjects Database Application

88

The Movies application specifies default values for newly created Movie
objects using the display group,

movieDisplayGroup

.

1. Open

Main.java

in Project Builder.

2. Add the following constructor:

public Main() {

super();

MutableHashtable defaultValues = new MutableHashtable();

defaultValues.put("title", "New Movie Title");

movieDisplayGroup.setInsertedObjectDefaultValues(defaultValues);

}

This method assigns the value “New Movie Title” as the default value for
a new movie’s

title

attribute. When

movieDisplayGroup

inserts a new movie (as it

does when a user clicks the Insert button), it creates a new movie and
assigns this default value to that movie.

Setting a Date Format

To change the way that dates are displayed, you assign a date format to the
element that displays the dates.

1. Inspect the

dateReleased

text field, which is near the bottom of the Main

component window.

Notice that the text field has a

dateformat

attribute that is bound to the string

“%m/%d/%y”. This binding tells the text field that it’s displaying dates
and describes how to format them. The %m conversion specifier stands for
month as a decimal number, %d stands for day of the month, and %y
stands for year without century.

2. Change the

dateformat

value to the string (including the quotes)

"%d %b %Y"

.

This date format displays dates such as 3 Sep 1997. The %b conversion
specifier stands for abbreviated month name, and %Y stands for year with
century. You can create your own date formats with any of the conversion
specifiers defined for dates. For more information, see the CalendarDate
class specification in the Foundation Framework Reference.

Advertising