Tapestry之前的概念,怎么建新工程,关于一些基础,就不说了,我是看的英文,觉得有些东西还不错,就直接照我的理解搞过来了。理解难免有偏差。
这里涉及两个页面 start.tml & another.tml
start.tml有一个currenttime,对应类中的getCurrentTime(); 有一个输入框 一个提交按钮,提交message的值到another.tml。还有一个链接,到another.tml。
start.tml
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<head>
<title>Tapestry Start Page</title>
</head>
<body>
<h1>Tapestry Start Page</h1>
<p> The current date and time is: ${currentTime}. </p>
<p> The same date and time in milliseconds is:
${currentTime.time}. </p>
<p> And here is the hash code for it:
${currentTime.hashCode()}. </p>
<p>
<t:PageLink t:page="Another">Go to Another
page</t:PageLink>
</p>
<p>Submit a message:</p>
<t:form t:id="userInputForm">
<t:textfield t:value="message"/>
<input type="submit" value="Submit"/>
</t:form>
</body>
</html>
Start.java
package com.packtpub.t5first.pages;
import java.util.Date;
import org.apache.tapestry.annotations.InjectPage;
import org.apache.tapestry.annotations.OnEvent;
/**
* Start page of application t5first.
*/
public class Start
{
private int someValue = 12345;
private String message="initial value";
@InjectPage
private Another another;
public int getSomeValue()
{
return someValue;
}
public void setSomeValue(int value)
{
this.someValue = value;
}
public Date getCurrentTime()
{
return new Date();
}
public String getMessage()
{
return message;
}
public void setMessage(String message)
{
System.out.println("Setting the message: " + message);
this.message = message;
}
@OnEvent(value="submit", component="userInputForm")
Object onFormSubmit()
{
System.out.println("Handling form submission!");
another.setPassedMessage(message);
return another;
}
}
another.tml
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<head>
<title>Another Page</title>
</head>
<body>
<h1>Another Page</h1>
<p>Received a new message: ${passedMessage}</p>
<p>
<t:PageLink t:page="Start">Back to the Start
page</t:PageLink>
</p>
</body>
</html>
Another.java
package com.packtpub.t5first.pages;
public class Another
{
private String passedMessage;
public String getPassedMessage()
{
return passedMessage;
}
public void setPassedMessage(String passedMessage)
{
this.passedMessage = passedMessage;
}
}