Showing posts with label Tapestry. Show all posts
Showing posts with label Tapestry. Show all posts

Tapestry Grid Example


Grid

A Grid component represents tablular data, it can be create very easily in tapestry. The Grid component is almost same as BeanEditor component, they are both based on the same underlying concept and sharing some codes.
Grid component class  is org.apache.tapestry5.corelib.components.Grid

Grid Example

Here is one simple example to edit a bean with BeanEditForm and using Grid to see the output.

a. Using BeanEditForm to create/update data
b. Using Grid to view the data
Create 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"/>
<t:grid source="personbeans"/>
</body>

</html>
Create person object
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 backend java file for template
package vinod.test.pages;

import java.util.ArrayList;
import java.util.List;

import vinod.test.model.Person;

public class BeanEditForm {
Person person = new Person();
List<Person> personbeans = new ArrayList<Person>();

public List<Person> getPersonbeans() {
return this.personbeans;
}

public void setPersonbeans(List<Person> personbeans) {
this.personbeans = personbeans;
}

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

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

Object onSuccess() {
System.out.println("Submit button was pressed!");
personbeans.add(person);

return BeanEditForm.class;
}
}
Output

Reference:

Tapestry BeanEditForm Example


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:

Tapestry BeanDisplay Example


BeanDisplay

BeanDisplay is part of tapestry core library and it used to display the properties of a bean. In the previous two posts we saw how to create the projects ,templates and pages. Let us see the BeanDisplay how it is working

BeanDisplay Example
1. Create the template (BeanDisplay.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: Bean display example
<t:beandisplayobject="person">
</t:beandisplay>
</body>
</html>
2. Create 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 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 java class for the template
package vinod.test.pages;

import vinod.test.model.Person;

public class BeanDisplay {

Person person = new Person("vinod", "Bangalore", "India");

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

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

}
Run the application and see the output

Reference 

Tapestry Simple Components Example

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 :)


Building Tapestry Application

Building Tapestry Application

Softwares required
1. Eclipse IDE
2. JDK 1.7
3. Tomcat 7.0
4. Maven 3
Create Maven Project with quickstart Archetype
Run the below command in the command prompt  and enter groupId,artifactId and version details, once the archetype is generated import that project in to your eclipse project.
we need to select the quick start archetype.
mvn archetype:generate -DarchetypeCatalog=http://tapestry.apache.org
Build the project and deploy in to tomcat server or use the eclipse run on server option to directly run,
  
Project structure 

 


Confusion Matrix + Precision/Recall (Super Simple, With Examples)

  Confusion Matrix + Precision/Recall (Super Simple, With Examples) 1) Binary Classification Setup Binary classification means the model p...

Featured Posts