ListView<Greeting> messages = new ListView<Greeting>("messages", latestGreetings)
{
@Override
protected void populateItem(ListItem<Greeting> item)
{
Greeting greeting = item.getModel().getObject();
String email = greeting.getAuthor() != null ? greeting.getAuthor().getNickname() : "An anonymous person ";
item.add(new Label("author", email));
item.add(new Label("message", greeting.getContent()));
}
};
add(messages);
Form<String> signForm = new Form<String>("sign-form", new Model<String>())
{
private TextArea<String> contentField;
{
contentField = new TextArea<String>("sign-content", new Model<String>(""));
add(contentField);
}
@Override
protected void onSubmit()
{
String content = contentField.getModelObject();
Date date = new Date();
Greeting greeting = new Greeting(user, content, date);
Guestbook.this.greetingRepo.persist(greeting);
contentField.setModelObject("");
// This causes a redirect to a clean page and URL, rather than rendering to the state of the
// current page which we don't care about here.