Searching...
Wednesday, 19 September 2012

Tapestry BeanEditForm Example

23:34

BeanEditForm

A component that creates an entire form editing the properties of a particular bean. (org.apache.tapestry5.corelib.components.BeanEditForm)
Here is one simple example to edit a bean with BeanEditForm from template page
Create a 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"/>
</body>
</html>
Create a model class
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 back end java class for template
package vinod.test.pages;

import vinod.test.model.Person;

public class BeanEditForm {

Person person = new Person();

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

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

Object onSuccess() {
System.out.println("Submit button was pressed!");
System.out.println("person Bean details" + person.toString());
// Here we can call DAO and update Bean details
return BeanEditForm.class;
}
}
Output

Reference:

0 comments: