第二十一讲:tapestry的LinkSubmit等同于submit来使用

tapestry的LinkSubmit其实就等同于一个submit按钮,它的存在可使前端开发很容易的修改<a>样式,非常容易做出好的按钮样式。源码如下:

LinkSubmits1.java

/**
* 项目名称:TapestryStart
* 开发模式:Maven+Tapestry5.x+Tapestry-hibernate+Mysql
* 网址: http://www.flywind.org
* 版本:1.0
* 编写:飞风
* 时间:2012-02-29
*/
package com.tapestry.app.pages;
 
import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.corelib.components.Form;
import org.apache.tapestry5.corelib.components.TextField;
 
public class LinkSubmits1 {
@Persist
@Property
private String firstName;
 
@Persist
@Property
private String lastName;
 
@Persist
@Property
private String selectName;
 
@Component(id = "names")
private Form form;
 
@Component(id = "firstName")
private TextField firstNameField;
 
@Component(id = "lastName")
private TextField lastNameField;
 
void onValidateFromNames() {
if (firstName == null || firstName.trim().equals("")) {
form.recordError(firstNameField, "First Name is required.");
}
if (lastName == null || lastName.trim().equals("")) {
form.recordError(lastNameField, "Last Name is required.");
}
}
 
Object onSuccess() {
selectName = firstName + lastName;
return this;
}
}
 

LinkSubmits1.tml

<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">
${selectName}
<form t:type="form" t:id="names" style="border: medium solid gray">
<t:errors/>
<table>
<tr>
<td>姓:</td>
<td><input t:type="TextField" t:id="firstName" t:validate="required"/></td>
</tr>
<tr>
<td>名:</td>
<td><input t:type="TextField" t:id="lastName" t:validate="required"/></td>
</tr>
<tr>
<td></td>
<td><t:linksubmit t:id="newlinksubmit">提交显示姓名</t:linksubmit></td>
</tr>
</table>
  </form>
</html>

http://localhost/linkSubmit/linkSubmit

你可能感兴趣的:(第二十一讲:tapestry的LinkSubmit等同于submit来使用)