
April 2009
March 2009
December 2008
October 2008
September 2008
August 2008
July 2008
June 2008
I’ve been spending a lot of time on Wicket lately for some exciting things that will be coming soon from Me.dium. One cool trick I started using the ListView. If you’ve come from PHP or any other web language, you know the drill– display query data from the database on a web page.
Here’s a simple implementation of the ListView to help you get started. I’m going to take a list of employees and output them to the screen. This tutorial assumes you know the basics of how Wicket works. This is the portion where we’re adding components to the display piece.
EmployeesPage.java
//Now I’ll populate the ListView with the query results
add(new ListView(”employeesRptr”, employees) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(ListItem item) {
User employee = (User) item.getModelObject();
// image display
item.add(new StaticImage(”profilePic”, new Model(employee.getPicture())));
// name display
StringBuilder name = new StringBuilder();
name.append(employee.getFirstName());
name.append(” “);
name.append(employee.getLastName());
item.add(new Label(”profileName”, name.toString()));
// location display
item.add(new Label(”profileLocation”, employee.getLocation()));
}
});
Now for the display:
EmployeesPage.html
<span wicket:id=”employeesRptr”>
<img wicket:id=”profilePic” border=”0″ />
<p class=”name” wicket:id=”profileName”>Joe Schmo</p>
<p class=”location” wicket:id=”profileLocation”>location</p>
</span>
Enjoy!
Tags: frameworks, Java, reference, wicket
« Newer Post Older Post »