Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Made images big enough to see

...

Code Block
languagejava
titlesrc/main/java/com/example/tutorial/entities/Address.java
package com.example.tutorial.entities;

import com.example.tutorial.data.Honorific;

public class Address
{
  public Honorific honorific;

  public String firstName;

  public String lastName;

  public String street1;

  public String street2;

  public String city;

  public String state;

  public String zip;

  public String email;

  public String phone;
}

We also need to define the enum type, Honorific:

...

So ... why is the class named "CreateAddress" and not simply "Create"? Actually, we could have named it "Create", and the application would still work, but the longer class name is equally valid. Tapestry noticed the redundancy in the class name (com.example.tutorial.pages.address.CreateAddress) and just stripped out the redundant suffix

...

. Tapestry also checks for redundant prefixes. In addition, the long name, "address/CreateAddress"

...

.

 would also work.

Eventually, your application will probably have more entities: perhaps you'll have a "user/Create" page and a "payment/Create" page and an "account/Create" page. You could have a bunch of different classes all named Create spread across a number of different packages. That's legal Java, but it isn't ideal. You may find yourself accidentally editing the Java code for creating an Account when your really want to be editing the code for creating a Payment.

...

When you refresh the page, you'll see the following:

Image RemovedImage Added

Tapestry's done quite a bit of work here. It has created a form that includes a field for each property. Further, its seen that the honorific property is an enumerated type, and presented that as a drop-down list.

...

Code Block
languagexml
titleCreateAddress.tml (partial)
  <t:beaneditform object="address"
    reorder="honorific,firstName,lastName,street1,street2,city,state,zip,email,phone" />

Image RemovedImage Added

Customizing labels

...

Since this is a new file (and not a change to an existing file), you may have to restart Jetty to force Tapestry to pick up the change.

Image Modified
Create Address form with field labels corrected

...

The final result shows the reformatting and relabeling:

Image Modified
Create Address form with proper labels

...

Let's give it a try; restart the application and enter an "abc" for the zip code.

Image Modified
Regexp validation

...

Refresh the page and submit again:

Image Modified

Regexp validation with corrected message

...

By now you are likely curious about what happens after the form submits successfully (without validation errors), so that's what we'll focus on next.

...

 

...

Wiki Markup
{scrollbar}