Added create-edition.xhtml and supporting JSF and EJB
index.xhtml lists all future editions
diff --git a/Temporal EJB/ejbModule/temporal/ejb/PersonService.java b/Temporal EJB/ejbModule/temporal/ejb/PersonService.java
index 56b7136..98422e5 100644
--- a/Temporal EJB/ejbModule/temporal/ejb/PersonService.java
+++ b/Temporal EJB/ejbModule/temporal/ejb/PersonService.java
@@ -24,4 +24,8 @@
     List<Person> getAllCurrent();
 
     List<Person> getAllAtT2();
+
+    List<Person> getAllEditions();
+
+    void create(long id, String name, long effective);
 }
diff --git a/Temporal EJB/ejbModule/temporal/ejb/PersonServiceBean.java b/Temporal EJB/ejbModule/temporal/ejb/PersonServiceBean.java
index 06cdc26..a475a7f 100644
--- a/Temporal EJB/ejbModule/temporal/ejb/PersonServiceBean.java
+++ b/Temporal EJB/ejbModule/temporal/ejb/PersonServiceBean.java
@@ -15,6 +15,8 @@
 import java.util.List;
 
 import javax.ejb.Stateless;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
 import javax.persistence.EntityManager;
 import javax.persistence.PersistenceContext;
 import javax.persistence.TypedQuery;
@@ -64,4 +66,27 @@
 
         return tem.createQuery("SELECT p FROM Person p", Person.class).getResultList();
     }
+
+    @TransactionAttribute(TransactionAttributeType.REQUIRED)
+    public void create(long id, String name, long effective) {
+        TemporalEntityManager tem = TemporalEntityManager.getInstance(getEntityManager());
+        tem.setEffectiveTime(effective);
+        
+        Person effectivePerson = tem.find(Person.class, id);
+        
+        if (effectivePerson == null) {
+            throw new IllegalArgumentException("No current person found for id: " + id);
+        }
+        if (effectivePerson.getEffectivity().getStart() < effective) {
+            Person editionPerson = tem.newEdition(effectivePerson);
+            editionPerson.setName(name);
+        }
+    }
+
+    @Override
+    public List<Person> getAllEditions() {
+        TemporalEntityManager tem = TemporalEntityManager.getInstance(getEntityManager());
+
+        return tem.createQuery("SELECT p FROM PersonEditionView p", Person.class).getResultList();
+    }
 }
diff --git a/Temporal Entity Example/src/temporal/TemporalEntityManager.java b/Temporal Entity Example/src/temporal/TemporalEntityManager.java
index f423799..4acc081 100644
--- a/Temporal Entity Example/src/temporal/TemporalEntityManager.java
+++ b/Temporal Entity Example/src/temporal/TemporalEntityManager.java
@@ -233,9 +233,7 @@
 
         // Flush the transaction so that any changes made to the new edition are
         // tracked and the EditionSet can be properly populated at commit.
-        if (getEntityManager().getTransaction().isActive()) {
-            getEntityManager().flush();
-        }
+        getEntityManager().flush();
 
         if (editionDesc.hasWrapperPolicy() && !editionDesc.getWrapperPolicy().isWrapped(edition)) {
             edition = (TemporalEntity<T>) editionDesc.getWrapperPolicy().wrapObject(edition, session);
diff --git a/Temporal WAR/.metadata/WebContent/WEB-INF/faces-config.pageflow b/Temporal WAR/.metadata/WebContent/WEB-INF/faces-config.pageflow
index c3be97b..ca50b74 100644
--- a/Temporal WAR/.metadata/WebContent/WEB-INF/faces-config.pageflow
+++ b/Temporal WAR/.metadata/WebContent/WEB-INF/faces-config.pageflow
@@ -1,2 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<pageflow:Pageflow xmlns:pageflow="http://www.sybase.com/suade/pageflow" id="pf13327765718510" configfile="/Temporal WAR/WebContent/WEB-INF/faces-config.xml"/>
+<pageflow:Pageflow xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pageflow="http://www.sybase.com/suade/pageflow" id="pf13327765718510" configfile="/Temporal WAR/WebContent/WEB-INF/faces-config.xml">
+  <nodes xsi:type="pageflow:PFPage" name="index.xhtml" x="203" y="228" id="pf13329388041990" inlinks="pf13329388041991" path="/index.xhtml"/>
+  <nodes xsi:type="pageflow:PFPage" name="create-edition.xhtml" x="742" y="277" id="pf13329388041992" outlinks="pf13329388041991" path="/create-edition.xhtml"/>
+  <links id="pf13329388041991" target="pf13329388041990" source="pf13329388041992" outcome="success"/>
+</pageflow:Pageflow>
diff --git a/Temporal WAR/WebContent/WEB-INF/faces-config.xml b/Temporal WAR/WebContent/WEB-INF/faces-config.xml
index 1ff6b85..79ec278 100644
--- a/Temporal WAR/WebContent/WEB-INF/faces-config.xml
+++ b/Temporal WAR/WebContent/WEB-INF/faces-config.xml
@@ -1,14 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
-<faces-config
-    xmlns="http://java.sun.com/xml/ns/javaee"
-    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
-    version="2.0">
+<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
+	version="2.0">
 	<managed-bean>
 		<managed-bean-name>persistenceBean</managed-bean-name>
 		<managed-bean-class>temporal.web.PersistenceBean</managed-bean-class>
 		<managed-bean-scope>request</managed-bean-scope>
 	</managed-bean>
+	<managed-bean>
+		<managed-bean-name>createEditionBean</managed-bean-name>
+		<managed-bean-class>temporal.web.CreateEditionBean</managed-bean-class>
+		<managed-bean-scope>request</managed-bean-scope>
+	</managed-bean>
+	<navigation-rule>
+		<display-name>create-edition.xhtml</display-name>
+		<from-view-id>/create-edition.xhtml</from-view-id>
+		<navigation-case>
+			<from-outcome>success</from-outcome>
+			<to-view-id>/index.xhtml</to-view-id>
+		</navigation-case>
+	</navigation-rule>
 
 </faces-config>
diff --git a/Temporal WAR/WebContent/create-edition.xhtml b/Temporal WAR/WebContent/create-edition.xhtml
new file mode 100644
index 0000000..c63d243
--- /dev/null
+++ b/Temporal WAR/WebContent/create-edition.xhtml
@@ -0,0 +1,36 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml"
+	xmlns:ui="http://java.sun.com/jsf/facelets"
+	xmlns:h="http://java.sun.com/jsf/html"
+	xmlns:f="http://java.sun.com/jsf/core">
+
+<f:loadBundle basename="resources.application" var="msg" />
+
+<head>
+<title>Temporal Example</title>
+</head>
+
+<body>
+	<h1>Temporal Example</h1>
+
+	<p>
+		<h:form>
+
+			<h:panelGrid columns="2" border="1">
+				<h:outputText value="Id:"></h:outputText>
+				<h:inputText id="id" value="#{createEditionBean.id}" />
+				<h:outputText value="Effective:"></h:outputText>
+				<h:inputText id="effective" value="#{createEditionBean.effective}" />
+				<h:outputText value="Name:"></h:outputText>
+				<h:inputText id="name" value="#{createEditionBean.name}" />
+				<f:facet name="footer" >
+					<h:commandButton action="#{createEditionBean.create}"
+						value="Create" />
+				</f:facet>
+			</h:panelGrid>
+		</h:form>
+	</p>
+</body>
+</html>
diff --git a/Temporal WAR/WebContent/index.xhtml b/Temporal WAR/WebContent/index.xhtml
index d51674e..0148385 100644
--- a/Temporal WAR/WebContent/index.xhtml
+++ b/Temporal WAR/WebContent/index.xhtml
@@ -17,6 +17,8 @@
 
 	<p>
 		<h:form>
+		
+		
 			<h:dataTable var="person" value="#{persistenceBean.current}"
 				border="1" bgcolor="whitesmoke" width="400">
 				<f:facet name="header">
@@ -46,7 +48,7 @@
 			<h:dataTable value="#{persistenceBean.atT2}" var="person"
 				bgcolor="whitesmoke" border="2" width="400">
 				<f:facet name="header">
-					<h:outputText value="Future Person Editions"></h:outputText>
+					<h:outputText value="Future Person Editions @T2"></h:outputText>
 				</f:facet>
 				<h:column>
 					<f:facet name="header">CID</f:facet>
@@ -70,7 +72,34 @@
 				</h:column>
 			</h:dataTable>
 
+			<h:dataTable value="#{persistenceBean.allEditions}" var="person"
+				bgcolor="whitesmoke" border="2" width="400">
+				<f:facet name="header">
+					<h:outputText value="All Future Person Editions"></h:outputText>
+				</f:facet>
+				<h:column>
+					<f:facet name="header">CID</f:facet>
+					<h:outputText value="#{person.continuityId}" />
+				</h:column>
+				<h:column>
+					<f:facet name="header">ID</f:facet>
+					<h:outputText value="#{person.id}" />
+				</h:column>
+				<h:column>
+					<f:facet name="header">Name</f:facet>
+					<h:outputText value="#{person.name}" />
+				</h:column>
+				<h:column>
+					<f:facet name="header">DOB</f:facet>
+					<h:outputText value="#{person.dateOfBirth}" />
+				</h:column>
+				<h:column>
+					<f:facet name="header">Effectivity</f:facet>
+					<h:outputText value="#{person.effectivity}" />
+				</h:column>
+			</h:dataTable>
 		</h:form>
+
 	</p>
 </body>
 </html>
diff --git a/Temporal WAR/src/temporal/web/CreateEditionBean.java b/Temporal WAR/src/temporal/web/CreateEditionBean.java
new file mode 100644
index 0000000..c28a14f
--- /dev/null
+++ b/Temporal WAR/src/temporal/web/CreateEditionBean.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2011-2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the 
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
+ * which accompanies this distribution. 
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at 
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *      dclarke - Bug 361016: Future Versions Examples
+ ******************************************************************************/
+package temporal.web;
+
+import javax.ejb.EJB;
+import javax.faces.bean.ManagedBean;
+
+import model.Person;
+import temporal.ejb.PersonService;
+
+@ManagedBean
+public class CreateEditionBean {
+
+    private long id;
+    
+    private String name;
+    
+    private long effective;
+
+    @EJB
+    private PersonService service;
+
+    public PersonService getService() {
+        return service;
+    }
+
+    public void setService(PersonService service) {
+        this.service = service;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public long getEffective() {
+        return effective;
+    }
+
+    public void setEffective(long effective) {
+        this.effective = effective;
+    }
+
+    public String create() {
+        getService().create(getId(), getName(), getEffective());
+        return "success";
+    }
+}
diff --git a/Temporal WAR/src/temporal/web/PersistenceBean.java b/Temporal WAR/src/temporal/web/PersistenceBean.java
index c90c13a..b81b6de 100644
--- a/Temporal WAR/src/temporal/web/PersistenceBean.java
+++ b/Temporal WAR/src/temporal/web/PersistenceBean.java
@@ -28,6 +28,7 @@
 
     private List<Person> atT2;
     
+    private List<Person> allEditions;
     @EJB
     private PersonService service;
 
@@ -52,4 +53,11 @@
         }
         return this.atT2;
     }
+
+    public List<Person> getAllEditions() {
+        if (this.allEditions == null) {
+            this.allEditions = getService().getAllEditions();
+        }
+        return this.allEditions;
+    }
 }