Example usage for org.apache.wicket.markup.html.list ListView modelChanged

List of usage examples for org.apache.wicket.markup.html.list ListView modelChanged

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.list ListView modelChanged.

Prototype

public final void modelChanged() 

Source Link

Document

Called to indicate that the model content for this component has been changed

Usage

From source file:net.java.ao.blog.pages.ViewPost.java

License:Apache License

public ViewPost(PageParameters params) {
    final Post post = ((BlogApplication) getApplication()).getEntityManager().get(Post.class,
            Integer.parseInt((String) params.get("item")));

    pageTitle = post.getBlog().getName() + ": " + post.getTitle();
    postedFormatted = DateFormat.getDateTimeInstance().format(post.getPublished().getTime());

    Link indexLink = new BookmarkablePageLink("indexLink", Index.class);
    add(indexLink);//w w w  . ja v a 2 s .  c o m

    indexLink.add(new Label("blogTitle", new PropertyModel(post.getBlog(), "name")));

    add(new Label("pageTitle", new PropertyModel(this, "pageTitle")));
    add(new Label("pageHeader", new PropertyModel(post, "title")));

    add(new PageLink("editPostLink", new EditPost(this, post.getBlog(), post)));

    add(new Label("posted", new PropertyModel(this, "postedFormatted")));

    add(new MultiLineLabel("text", new PropertyModel(post, "text")));

    final ListView comments = new ListView("comments", Arrays.asList(post.getComments())) {
        @Override
        protected void populateItem(ListItem item) {
            Comment comment = (Comment) item.getModelObject();

            item.add(new Label("commentBy", new PropertyModel(comment, "name")));
            item.add(new MultiLineLabel("comment", new PropertyModel(comment, "comment")));
        }
    };
    add(comments);

    final CommentBean commentBean = new CommentBean();
    Form commentForm = new Form("commentForm") {
        @Override
        protected void onSubmit() {
            Comment comment = null;
            try {
                comment = ((BlogApplication) getApplication()).getEntityManager().create(Comment.class);
            } catch (SQLException e) {
                e.printStackTrace();
                return;
            }

            comment.setName(commentBean.getName());
            comment.setComment(commentBean.getComment());
            comment.setPost(post);

            comments.setList(Arrays.asList(post.getComments()));
            comments.modelChanged();
        }
    };
    add(commentForm);

    commentForm.add(new TextField("name", new PropertyModel(commentBean, "name")));
    commentForm.add(new TextArea("commentText", new PropertyModel(commentBean, "comment")));
}