Let us see this by displaying the International Greets in a Grid.
In /src/main/java/org/confucius, create a class Greet.java, like this:
package org.confucius;
public class Greet {
private String language;
private String greeting;
public Greet(String language, String greeting) {
this.language = language;
this.greeting = greeting;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getGreeting() {
return greeting;
}
public void setGreeting(String greeting) {
this.greeting = greeting;
}
}
Update InternationalGreets.java with a method to return a List of Greets, like this:
package org.confucius.pages;
import java.util.ArrayList;
import java.util.List;
import org.apache.tapestry5.annotations.Property;
import org.confucius.Greet;
public class InternationalGreets {
@Property
private Greet greet;
public List<Greet> getInternationalGreetsList(){
List<Greet> greetList = new ArrayList<Greet>();
Greet englishGreet = new Greet("English", "Hello World!");
greetList.add(englishGreet);
Greet frenchGreet = new Greet("French", "Bonjour tout le Monde!");
greetList.add(frenchGreet);
Greet italianGreet = new Greet("Italian", "Buongiorno a Tutti!");
greetList.add(italianGreet);
Greet spanishGreet = new Greet("Spanish", "Hola Mundo!");
greetList.add(spanishGreet);
Greet swahiliGreet = new Greet("Swahili", "Jambo!");
greetList.add(swahiliGreet);
return greetList;
}
}
Update InternationaGreets.tml to use the Grid component to display the greets, like this:
<html t:type="layout" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
<body>
<t:grid source="internationalGreetsList" row="greet"/>
</body>
</html>
Since we are using the default Grid, i.e. there are no specific instructions, Grid will show each property of the Greet object in the order in which it appears in Greet.java. Each column will be sortable by default.
If you rebuild and redeploy HelloWorldTapestry, you will see the International Greets in a sortable table.
No comments:
Post a Comment