[CONF] Apache Tapestry Using BeanEditForm To Create User Forms

2014-02-25 Thread Bob Harner (Confluence)














  


Bob Harner edited the page:
 


Using BeanEditForm To Create User Forms   




 Comment: Minor edits 


...
When you refresh the page, you'll see the following:
 
Tapestry 's has done quite a bit of work here. It has created a form that includes a field for each property. Further, its it has seen that the honorific property is an enumerated type, and presented that as a drop-down list.
...
The BeanEditForm must guess at the right order to present the fields; for public fields, they end up in alphabetical order



 Wiki Markup




 
{footnote}For standard JavaBeans properties, the BeanEditForm default is in the order in which the getter methods are defined in the class (it uses line number information, if available).{footnote}
 



.

A better order for these fields is the order in which they are defined in the Address class:
...
In Tapestry, when binding a parameter, the value you provide may include a prefix. The prefix guides Tapestry in how to interpret the rest of the the parameter value ... is it the name of a property? The id of a component? A message key? Most fields parameters have a default prefix, usually prop:, that is used when you fail to provide one (this helps to make the templates as terse as possible).
...



 Code Block








language
xml


 



  

[CONF] Apache Tapestry Using BeanEditForm To Create User Forms

2014-01-19 Thread Bob Harner (Confluence)














  


Bob Harner edited the page:
 


Using BeanEditForm To Create User Forms   




 Comment: Made images big enough to see 


...



 Code Block








title
src/main/java/com/example/tutorial/entities/Address.java


language
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 

[CONF] Apache Tapestry Using BeanEditForm To Create User Forms

2011-11-22 Thread confluence







Using BeanEditForm To Create User Forms
Page edited by Howard M. Lewis Ship


Comment:
Update for 5.3


 Changes (4)
 




...
{code:XML|title=src/main/resources/com/example/tutorial/pages/address/CreateAddress.tml} html t:type=layout title=Create New Address 
xmlns:t=http://tapestry.apache.org/schema/tapestry_5_1_0.xsd xmlns:t=http://tapestry.apache.org/schema/tapestry_5_3.xsd 
   emcoming soon .../em 
...
Tapestry is encouraging you to use a more descriptive name: Create{_}Address_, not just Create, but it isnt making you pay the cost (in terms of longer, uglier URLs). The URL to access the page will still be [http://localhost:8080/tutorial1/address/create].  
And remember, regardless of the name that Tapestry assigns to your page, the template file is named like the Java class itself: CreateAddress.tml.  
{info} Index pages work in folders as well. A class named com.example.tutorial.pages.address.AddressIndex would be given the name address/Index. However, Tapestry has special rules for pages named Index and the rendered URL would be [http://localhost:8080/tutorial1/address/]. In other words, you can place Index pages in any folder and Tapestry will build a short URL for that page ... and you _dont_ have to keep naming the classes Index (its confusing to have many classes with the same name, even across multiple packages); instead, you can name each index page after the package that contains it. Tapestry users a smart _convention_ to keep it all straight and generate short, to the point URLs. 
...
MR=Mr. MRS=Mrs. 
DR=Dr.{noformat} 
{noformat} 
 Notice that we dont have to include an option for MISS, because that is converted to Miss anyway. You might just want to include it for sake of consistency ... the point is, each option label is searched for separately. 
...


Full Content

Implementing the Hi-Lo Guessing GameTapestry TutorialUsing Tapestry With Hibernate

In the previous chapters, we saw how Tapestry can handle simple links, even links that pass information in the URL. In this chapter, we'll see how Tapestry can do the same, and quite a bit more, for HTML forms.

Form support in Tapestry is deep and rich, more than can be covered in a single chapter. However, we can show the basics, including some very common development patterns. To get started, let's create a simple address book application.

We'll start with the entity data, a simple object to store the information we'll need. These classes go in an entities sub-package. Unlike the use of the pages sub-package (for page component classes), this is not enforced by Tapestry; it's just a convention (but as we'll see shortly, a handy one).

Tapestry treats public fields as if they were JavaBeans properties; since the Address object is just "dumb data", there's no need to get carried away writing getters and setters. Instead, we'll define an entity that is all public fields:

src/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:

src/main/java/com/example/tutorial/data/Honorific.java

package com.example.tutorial.data;

public enum Honorific
{
  MR, MRS, MISS, DR
}



Address Pages

We're probably going to create a few pages related to addresses: pages for creating them, for editing them, for searching and listing them. We'll create a sub-folder, address, to hold them. Let's get started on the first of these pages, "address/Create" (that's the real name, including the slash  we'll see in a minute how that maps to classes and templates).

First, we'll update the Index.tml template, to create a link to the new page:

src/main/resources/com/example/tutorial/pages/Index.tml (partial)

h1Address Book/h1

ul
  lit:pagelink page="address/create"Create new address/t:pagelink/li
/ul





Now we need the address/Create page; lets start with an empty shell, just to test our navigation.

src/main/resources/com/example/tutorial/pages/address/CreateAddress.tml

html t:type="layout" title="Create New Address"
  xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"

  emcoming soon .../em

/html



And the corresponding class:

src/main/java/com/example/tutorial/tutorial/pages/address/CreateAddress.java

package 

[CONF] Apache Tapestry Using BeanEditForm To Create User Forms

2011-11-22 Thread confluence







Using BeanEditForm To Create User Forms
Page edited by Howard M. Lewis Ship


Comment:
Update for 5.3


 Changes (4)
 




...
{code:XML|title=src/main/resources/com/example/tutorial/pages/address/CreateAddress.tml} html t:type=layout title=Create New Address 
xmlns:t=http://tapestry.apache.org/schema/tapestry_5_1_0.xsd xmlns:t=http://tapestry.apache.org/schema/tapestry_5_3.xsd 
   emcoming soon .../em 
...
Tapestry is encouraging you to use a more descriptive name: Create{_}Address_, not just Create, but it isnt making you pay the cost (in terms of longer, uglier URLs). The URL to access the page will still be [http://localhost:8080/tutorial1/address/create].  
And remember, regardless of the name that Tapestry assigns to your page, the template file is named like the Java class itself: CreateAddress.tml.  
{info} Index pages work in folders as well. A class named com.example.tutorial.pages.address.AddressIndex would be given the name address/Index. However, Tapestry has special rules for pages named Index and the rendered URL would be [http://localhost:8080/tutorial1/address/]. In other words, you can place Index pages in any folder and Tapestry will build a short URL for that page ... and you _dont_ have to keep naming the classes Index (its confusing to have many classes with the same name, even across multiple packages); instead, you can name each index page after the package that contains it. Tapestry users a smart _convention_ to keep it all straight and generate short, to the point URLs. 
...
MR=Mr. MRS=Mrs. 
DR=Dr.{noformat} 
{noformat} 
 Notice that we dont have to include an option for MISS, because that is converted to Miss anyway. You might just want to include it for sake of consistency ... the point is, each option label is searched for separately. 
...


Full Content

Implementing the Hi-Lo Guessing GameTapestry TutorialUsing Tapestry With Hibernate

In the previous chapters, we saw how Tapestry can handle simple links, even links that pass information in the URL. In this chapter, we'll see how Tapestry can do the same, and quite a bit more, for HTML forms.

Form support in Tapestry is deep and rich, more than can be covered in a single chapter. However, we can show the basics, including some very common development patterns. To get started, let's create a simple address book application.

We'll start with the entity data, a simple object to store the information we'll need. These classes go in an entities sub-package. Unlike the use of the pages sub-package (for page component classes), this is not enforced by Tapestry; it's just a convention (but as we'll see shortly, a handy one).

Tapestry treats public fields as if they were JavaBeans properties; since the Address object is just "dumb data", there's no need to get carried away writing getters and setters. Instead, we'll define an entity that is all public fields:

src/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:

src/main/java/com/example/tutorial/data/Honorific.java

package com.example.tutorial.data;

public enum Honorific
{
  MR, MRS, MISS, DR
}



Address Pages

We're probably going to create a few pages related to addresses: pages for creating them, for editing them, for searching and listing them. We'll create a sub-folder, address, to hold them. Let's get started on the first of these pages, "address/Create" (that's the real name, including the slash  we'll see in a minute how that maps to classes and templates).

First, we'll update the Index.tml template, to create a link to the new page:

src/main/resources/com/example/tutorial/pages/Index.tml (partial)

h1Address Book/h1

ul
  lit:pagelink page="address/create"Create new address/t:pagelink/li
/ul





Now we need the address/Create page; lets start with an empty shell, just to test our navigation.

src/main/resources/com/example/tutorial/pages/address/CreateAddress.tml

html t:type="layout" title="Create New Address"
  xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"

  emcoming soon .../em

/html



And the corresponding class:

src/main/java/com/example/tutorial/tutorial/pages/address/CreateAddress.java

package 

[CONF] Apache Tapestry Using BeanEditForm To Create User Forms

2011-11-22 Thread confluence







Using BeanEditForm To Create User Forms
Page edited by Howard M. Lewis Ship


Comment:
More 5.3 updates


 Changes (17)
 




...
!create-address-reordered.png|thumbnail!  
Ultimately, however we will be using the BeanEditForm with the Address entity on several pages, and dont want to have to reiterate that list of properties every time.   
h3. 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.  
!address-v3.png|border=1,width=760,height=446! Create Address form with field labels corrected 
...
 {code:XML} 
  t:beaneditform submitlabel=message:submit-label object=address/{code} 
  t:beaneditform object=address submitlabel=message:submit-label reorder=honorific,firstName,lastName,street1,street2,city,state,zip,email,phone / {code} 
 And then define the submit-label key in the message catalog:  {noformat} 
submit-label=Create Address{noformat} 
{noformat} 
 At then end of the day, the exact same HTML is sent to the client, regardless of whether you include the label text directly in the template, or indirectly in the message catalog. In the long term, the latter approach will work better if you later chose to internationalize your application. 
...
The BeanEditForm checks for a Tapestry-specific annotation, @org.apache.tapestry5.beaneditor.Validate, on the getter _or_ setter method of each property.  
Update the getter methods for the lastName, firstName, street1, city, state and zip fields, adding a @Validate annotation to each: 
 {code}   @Validate(required) 
public String getFirstName() firstName; 
  { return firstName;   } 
{code}  
...
You can apply multiple validations, by separating the validator names with commas. Some validators can be configured (with an equals sign). Thus you might say required,minLength=5 for a field that must be specified, and must be at least five characters long.  
{warning} You can easily get confused when you make a change to an entity class, such as adding the @Validate annotatation, and _not_ see the result in the browser. Only component classes, and (most) classes in the Tapestry services layer, are live-reloaded.  Data and entity objects are not reloaded, so this is one area where you need to stop and restart Jetty to see the change. {warning}  
Restart the application, and refresh your browser, then hit the submit button.  
!address-v6.png|border=1,width=760,height=482! 
  
...
{code}   @Validate(required,regexp=^\\d{5}(-\\d{4})?$) 
public String getZip() zip; 
  { return zip;   } 
{code}  
...
 {noformat} 
zip-regexp-message=Zip Codes are five or nine digits.  Example: 02134 or 90125-1655.{noformat} 
{noformat} 
 Refresh the page and submit again:  
!address-v8.png|border=1,width=760,height=482! 
  
...
{code}   @Validate(required,regexp) 
public String getZip() zip; 
  { return zip;   } 
{code}  
...
{noformat} zip-regexp=^\\d{5}(-\\d{4})?$ 
zip-regexp-message=Zip Codes are five or nine digits.  Example: 02134 or 90125-1655.{noformat} 
{noformat} 
 After a restart youll see the ... the same behavior. But when we start creating more complicated regular expressions, itll be much, much nicer to put them in the message catalog rather than inside the annotation value. And inside the message catalog, you can change and tweak the regular expressions without having to restart the application each time. 
...


Full Content

Implementing the Hi-Lo Guessing GameTapestry TutorialUsing Tapestry With Hibernate

In the previous chapters, we saw how Tapestry can handle simple links, even links that pass information in the URL. In this chapter, we'll see how Tapestry can do the same, and quite a bit more, for HTML forms.

Form support in Tapestry is deep and rich, more than can be covered in a single chapter. However, we can show the basics, including some very common development patterns. To get started, let's create a simple address book application.

We'll start with the entity data, a simple object to store the information we'll need. These classes go in an entities sub-package. Unlike the use of the pages sub-package (for page 

[CONF] Apache Tapestry Using BeanEditForm To Create User Forms

2011-10-19 Thread confluence







Using BeanEditForm To Create User Forms
Page edited by Howard M. Lewis Ship


Comment:
Use JavaDoc not 5.2 component reference


 Changes (1)
 




...
h1. Using the BeanEditForm Component  
Time to start putting together the logic for this form.  Tapestry has a specific component for client-side Forms: the [Form|http://tapestry.apache.org/current/tapestry-core/ref/org/apache/tapestry5/corelib/components/Form.html] [Form|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/Form.html] component, as well as components for form controls, such as [Checkbox|http://tapestry.apache.org/current/tapestry-core/ref/org/apache/tapestry5/corelib/components/Checkbox.html] [Checkbox|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/Checkbox.html] and [TextField|http://tapestry.apache.org/current/tapestry-core/ref/org/apache/tapestry5/corelib/components/TextField.html]. [TextField|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/TextField.html].  Well cover those in a bit more detail later .. instead, were again going to let Tapestry do the heavy lifting for us, via the [BeanEditForm|http://tapestry.apache.org/current/tapestry-core/ref/org/apache/tapestry5/corelib/components/BeanEditForm.html] [BeanEditForm|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/BeanEditForm.html] component. 
 Add the following to the CreateAddress template (replacing the coming soon ... message): 
...


Full Content

Implementing the Hi-Lo Guessing GameTapestry TutorialUsing Tapestry With Hibernate

In the previous chapters, we saw how Tapestry can handle simple links, even links that pass information in the URL. In this chapter, we'll see how Tapestry can do the same, and quite a bit more, for HTML forms.

Form support in Tapestry is deep and rich, more than can be covered in a single chapter. However, we can show the basics, including some very common development patterns. To get started, let's create a simple address book application.

We'll start with the entity data, a simple object to store the information we'll need. These classes go in an entities sub-package. Unlike the use of the pages sub-package (for page component classes), this is not enforced by Tapestry; it's just a convention (but as we'll see shortly, a handy one).

Tapestry treats public fields as if they were JavaBeans properties; since the Address object is just "dumb data", there's no need to get carried away writing getters and setters. Instead, we'll define an entity that is all public fields:

src/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:

src/main/java/com/example/tutorial/data/Honorific.java

package com.example.tutorial.data;

public enum Honorific
{
  MR, MRS, MISS, DR
}



Address Pages

We're probably going to create a few pages related to addresses: pages for creating them, for editing them, for searching and listing them. We'll create a sub-folder, address, to hold them. Let's get started on the first of these pages, "address/Create" (that's the real name, including the slash  we'll see in a minute how that maps to classes and templates).

First, we'll update the Index.tml template, to create a link to the new page:

src/main/resources/com/example/tutorial/pages/Index.tml (partial)

h1Address Book/h1

ul
  lit:pagelink page="address/create"Create new address/t:pagelink/li
/ul





Now we need the address/Create page; lets start with an empty shell, just to test our navigation.

src/main/resources/com/example/tutorial/pages/address/CreateAddress.tml

html t:type="layout" title="Create New Address"
  xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"

  emcoming soon .../em

/html



And the corresponding class:

src/main/java/com/example/tutorial/tutorial/pages/address/CreateAddress.java

package com.example.tutorial.pages.address;

public class CreateAddress
{

}



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



  

[CONF] Apache Tapestry Using BeanEditForm To Create User Forms

2010-12-09 Thread confluence







Using BeanEditForm To Create User Forms
File attached by  Howard M. Lewis Ship




create-address-initial.png
(61 kB image/png)



   
Change Notification Preferences
   
   View Attachments









[CONF] Apache Tapestry Using BeanEditForm To Create User Forms

2010-12-09 Thread confluence







Using BeanEditForm To Create User Forms
File attached by  Howard M. Lewis Ship




create-address-reordered.png
(61 kB image/png)



   
Change Notification Preferences
   
   View Attachments









[CONF] Apache Tapestry Using BeanEditForm To Create User Forms

2010-12-01 Thread confluence







Using BeanEditForm To Create User Forms
Page edited by Howard M. Lewis Ship


 Changes (4)
 



{tutorialnav} {scrollbar} 
 
h2. Chapter 4: Forms in Tapestry  
...
By now you are likely curious about what happens _after_ the form submits successfully (without validation errors), so thats what well focus on next.  
[Continue on to Chapter 5: Forms in Tapestry, Part Two|TAPESTRY:Forms2] 
{tutorialnav} {scrollbar} 

Full Content

Implementing the Hi-Lo Guessing GameTapestry TutorialForms2

Chapter 4: Forms in Tapestry

In the previous chapters, we saw how Tapestry can handle simple links, even links that pass information in the URL. In this chapter, we'll see how Tapestry can do the same, and quite a bit more, for HTML forms.

Form support in Tapestry is deep and rich, more than can be covered in a single chapter. However, we can show the basics, including some very common development patterns. To get started, let's create a simple address book application.

We'll start with the entity data, a simple object to store the information we'll need. These classes go in an entities sub-package. Unlike the use of the pages sub-package (for page component classes), this is not enforced by Tapestry; it's just a convention (but as we'll see shortly, a handy one).

src/main/java/org/apache/tapestry5/tutorial/entities/Address.java

package org.apache.tapestry5.tutorial.entities;

import org.apache.tapestry5.tutorial.data.Honorific;

public class Address
{
  private Honorific honorific;

  private String firstName;

  private String lastName;

  private String street1;

  private String street2;

  private String city;

  private String state;

  private String zip;

  private String email;

  private String phone;

  public String getCity()
  {
return city;
  }

  public String getEmail()
  {
return email;
  }

  public String getFirstName()
  {
return firstName;
  }

  public Honorific getHonorific()
  {
return honorific;
  }

  public String getLastName()
  {
return lastName;
  }

  public String getPhone()
  {
return phone;
  }

  public String getState()
  {
return state;
  }

  public String getStreet1()
  {
return street1;
  }

  public String getStreet2()
  {
return street2;
  }

  public String getZip()
  {
return zip;
  }

  public void setCity(String city)
  {
this.city = city;
  }

  public void setEmail(String email)
  {
this.email = email;
  }

  public void setFirstName(String firstName)
  {
this.firstName = firstName;
  }

  public void setHonorific(Honorific honorific)
  {
this.honorific = honorific;
  }

  public void setLastName(String lastName)
  {
this.lastName = lastName;
  }

  public void setPhone(String phone)
  {
this.phone = phone;
  }

  public void setState(String state)
  {
this.state = state;
  }

  public void setStreet1(String street1)
  {
this.street1 = street1;
  }

  public void setStreet2(String street2)
  {
this.street2 = street2;
  }

  public void setZip(String zip)
  {
this.zip = zip;
  }
}


It's just a collection of getter and setter methods. We also need to define the enum type, Honorific:

src/main/java/org/apache/tapestry5/tutorial/data/Honorific.java

package org.apache.tapestry5.tutorial.data;

public enum Honorific
{
  MR, MRS, MISS, DR
}



Address Pages

We're probably going to create a few pages related to addresses: pages for creating them, for editing them, for searching and listing them. We'll create a sub-folder, address, to hold them. Let's get started on the first of these pages, "address/Create" (that's the real name, including the slash  we'll see in a minute how that maps to classes and templates).

First, we'll update the Index.tml template, to create a link for creating a new page:

src/main/webapp/Index.tml

h1Address Book/h1

ul
  lit:pagelink page="address/create"Create new address/t:pagelink/li
/ul



Now we need the page, let's start with an empty shell, just to test our navigation.

src/main/webapp/address/CreateAddress.tml

html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
  head
titleCreate New Address/title
  /head
  body

h1Create New Address/h1

emcoming soon .../em

  /body
/html



And the corresponding class:

src/main/java/org/apache/tapestry5/tutorial1/pages/address/CreateAddress.java

package org.apache.tapestry5.tutorial.pages.address;

public class CreateAddress
{

}



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: