String parentConversation = new FacesRequest("/page.xhtml") {
@Override
protected void invokeApplication() throws Exception {
Thing thing = new Thing();
thing.setName("thing");
EntityManager entityManager = (EntityManager) getValue("#{entityManager}");
entityManager.persist(thing);
Contexts.getConversationContext().set("thing", thing);
Manager.instance().beginConversation();
}
}.run();
new FacesRequest("/page.xhtml", parentConversation) {
}.run();
// nested conversation
String nestedId = new FacesRequest("/page.xhtml", parentConversation) {
@Override
protected void invokeApplication() throws Exception {
Manager.instance().beginNestedConversation();
}
}.run();
// update entity in nested conversation
new FacesRequest("/page.xhtml", nestedId) {
@Override
protected void invokeApplication() throws Exception {
Thing thing = (Thing) Contexts.getConversationContext().get("thing");
thing.setName("foo");
EntityManager entityManager = (EntityManager) getValue("#{entityManager}");
entityManager.flush();
}
}.run();
// end nested conversation
assert new FacesRequest("/page.xhtml", nestedId) {