Searching...
Wednesday, 19 September 2012

Tapestry Simple Components Example

14:43
In the previous post we done the setup for tapestry quick start archetype and started the server. This example we will see how to add TextField,PasswordField,ActionLink,Submit etc components
1. Project structure

























2. Create templates, in this example creating two templates (one is for login and another one is for success page)
Mylogin.tml
<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: Hello world
<t:form t:id="userInputForm">
<t:errors/>
<a t:id="select" t:type="actionlink">Action</a>
<table>
<tr>
<td>Enter your Name:</td>
<td>
<t:textfield t:value="Name" t:validate="required,minlength=3"/>
</td>
</tr>
<tr>
<td>
<t:label t:for="password">Enter your password</t:label>:</td>
<td>
<inputtype="text" t:id="password" t:type="PasswordField" t:value="password"/>
</td>
</tr>
<tr>
<td>
<inputtype="submit"value="Submit"/>
</td>
</tr>
</table>
</t:form>
</body>

</html>
LoginSuccess.tml
<html t:type="layout"title="Success vinod"
 xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"

      xmlns:p="tapestry:parameter">

<p>Login Successful ..</p>

</html>
3. Now we need to create the corresponding tapestry java pages in the backend
Mylogin.java
package vinod.test.pages;

import org.apache.tapestry5.annotations.OnEvent;

public class Mylogin {
private String name;
private String password;

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

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

public String getPassword() {
return this.password;
}

public void setPassword(String password) {
this.password = password;
}
@OnEvent(value = "submit", component = "userInputForm")
Object onFormSubmit() {
if (name.equals("vinod")) {
System.out.println("Login successful");
return LoginSuccess.class;
} else {
System.out.println("Loging faild");

return Mylogin.class;
}
}
}
LoginSuccess.java
package vinod.test.pages;

public class LoginSuccess {

}
Deploy/Run the application and see the below outputs :)


0 comments: