Package com.tapestry5book.pages.chapter12

Source Code of com.tapestry5book.pages.chapter12.Post2

package com.tapestry5book.pages.chapter12;

import com.tapestry5book.entities.Article;
import com.tapestry5book.entities.Blog;
import org.apache.tapestry5.alerts.AlertManager;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.hibernate.HibernateSessionManager;
import org.apache.tapestry5.hibernate.annotations.CommitAfter;
import org.apache.tapestry5.ioc.annotations.Inject;

public class Post2 {
    @Inject
    private HibernateSessionManager hibernateSessionManager;

    @Inject
    private AlertManager alertManager;

    @Property
    private Article article;

    @SessionState
    @Property
    private Blog blog;

    void onPrepare() {
        article = new Article();
    }

    @CommitAfter
    void onSuccess() {
        article.setBlog(blog);

        try {
            hibernateSessionManager.getSession().save(article);
            hibernateSessionManager.commit();
        } catch (RuntimeException e) {
            hibernateSessionManager.abort();
        }

        alertManager.info("Article saved successfully.");
    }
}
TOP

Related Classes of com.tapestry5book.pages.chapter12.Post2

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.