package webtier;

import java.util.Date;

import javax.ejb.EJB;
import javax.ejb.TransactionManagement;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;

import session.XaJpaDemoBean;
import domain.Customer;
import domain.Order;

/**
 * JSF Managed Bean for order
 * @author ian
 */
@ManagedBean
@TransactionManagement()
public class OrderWebBean {
	@EJB XaJpaDemoBean ejb;
	Customer customer;
	int orderQuantity;
	
	public String saveOrder() {
		Customer c = ejb.findCustomer(1);
		Order o = new Order();
		o.setDate(new Date());
		o.setQuantity(42);
		
		ejb.saveCustomerOrder(c, o, true);
		
		final FacesMessage facesMessage = new FacesMessage();
		facesMessage.setSummary("Added OK");
		facesMessage.setDetail("Saved order " + c + " " + o);
		FacesContext.getCurrentInstance().addMessage(null, facesMessage);
		return "done";
	}
	
	public String saveOrderFail() {
		Customer c = ejb.findCustomer(1);
		
		Order o2 = new Order();
		o2.setDate(new Date());
		o2.setQuantity(100);

		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("(Simulated failure: setRollBackOnly)"));
		
		ejb.getSessionContext().setRollbackOnly();
		ejb.saveCustomerOrder(c, o2, false);
		return "done"; // NOTREACHED
	}
}


@@ -1048,11 +1048,10 @@
 ity(
-100
+86
 );%0A%0A
@@ -1171,32 +1171,43 @@
 %09%0A%09%09
-ejb.getSessionContext().
+// The 3rd arg 'false' will invoke 
 setR

Remove invalid attempt to control ejb from outside. Demo fully works now.