Searching...
Wednesday, 19 September 2012

Tapestry Grid Example

23:45

Grid

A Grid component represents tablular data, it can be create very easily in tapestry. The Grid component is almost same as BeanEditor component, they are both based on the same underlying concept and sharing some codes.
Grid component class  is org.apache.tapestry5.corelib.components.Grid

Grid Example

Here is one simple example to edit a bean with BeanEditForm and using Grid to see the output.

a. Using BeanEditForm to create/update data
b. Using Grid to view the data
Create template
<html t:type="layout"title="TestArtifact Page"

xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"

xmlns:p="tapestry:parameter">

<body>

Vinod: Bean Editor example

<t:beaneditform t:id="person"/>
<t:grid source="personbeans"/>
</body>

</html>
Create person object
package vinod.test.model;
public class Person {
private String name;
private String address;
private String country;

public Person(String name, String address, String country) {
super();
this.name = name;
this.address = address;
this.country = country;
}

public Person() {
}

public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

public String getAddress() {
return this.address;
}

public void setAddress(String address) {
this.address = address;
}

public String getCountry() {
return this.country;
}

public void setCountry(String country) {
this.country = country;
}

}
Create backend java file for template
package vinod.test.pages;

import java.util.ArrayList;
import java.util.List;

import vinod.test.model.Person;

public class BeanEditForm {
Person person = new Person();
List<Person> personbeans = new ArrayList<Person>();

public List<Person> getPersonbeans() {
return this.personbeans;
}

public void setPersonbeans(List<Person> personbeans) {
this.personbeans = personbeans;
}

public Person getPerson() {
return this.person;
}

public void setPerson(Person person) {
this.person = person;
}

Object onSuccess() {
System.out.println("Submit button was pressed!");
personbeans.add(person);

return BeanEditForm.class;
}
}
Output

Reference:

0 comments: