/**
* 項目名稱:TapestryStart
* 開發模式:Maven+Tapestry5.x+Tapestry-hibernate+Mysql
* 版本:1.0
* 編寫:飛風
* 時間:2012-02-29
*/
package com.tapestry.app.pages;
import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.corelib.components.Form;
import org.apache.tapestry5.corelib.components.TextField;
public class Forms1 {
@Property
private String firstName;
@Property
private String lastName;
@Component(id="myForm")
private Form form;
@Component(id="firstName")
private TextField firstNameField;
@Component(id="lastName")
private TextField lastNameField;
@InjectPage
private Forms2 forms2;
void onValidateFromMyForm(){
if(firstName == null || firstName.trim().equals("")){
form.recordError(firstNameField, "姓不能爲空值!");
}
if(lastName == null || lastName.trim().equals("")){
form.recordError(lastNameField, "名字不能爲空值!");
}
}
Object onSuccess(){
forms2.setFirstName(firstName);
forms2.setLastName(lastName);
return forms2;
}
}
<html t:type="layout" title="tapestryStart Index" t:sidebarTitle="Framework Version"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd" xmlns:p="tapestry:parameter">
<t:form t:id="myForm">
<t:errors/>
姓:<input t:type="textfield" t:id="firstName" value="firstName"/><br/>
名:<input t:type="textfield" t:id="lastName" value="lastName"/><br/>
<input type="submit" value="提交"/>
</t:form>
</html>
/**
* 項目名稱:TapestryStart
* 開發模式:Maven+Tapestry5.x+Tapestry-hibernate+Mysql
* 版本:1.0
* 編寫:飛風
* 時間:2012-02-29
*/
package com.tapestry.app.pages;
import org.apache.tapestry5.annotations.Persist;
public class Forms2 {
private String firstName;
private String lastName;
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
}
<html t:type="layout" title="tapestryStart Index" t:sidebarTitle="Framework Version"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd" xmlns:p="tapestry:parameter">
用戶名:${firstName}${lastName}
<t:pagelink page="Forms1">返回</t:pagelink>
</html>
http://localhost/form/forms1