[seam-commits] Seam SVN: r11924 - in modules/remoting/trunk/examples/model/src/main: webapp and 1 other directory.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Thu Jan 7 04:04:32 EST 2010


Author: shane.bryzak at jboss.com
Date: 2010-01-07 04:04:32 -0500 (Thu, 07 Jan 2010)
New Revision: 11924

Modified:
   modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Person.java
   modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/PersonAction.java
   modules/remoting/trunk/examples/model/src/main/webapp/model.html
   modules/remoting/trunk/examples/model/src/main/webapp/style.css
Log:
example improvements


Modified: modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Person.java
===================================================================
--- modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Person.java	2010-01-07 07:39:41 UTC (rev 11923)
+++ modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Person.java	2010-01-07 09:04:32 UTC (rev 11924)
@@ -4,6 +4,7 @@
 import java.util.Collection;
 import java.util.Date;
 
+import javax.persistence.CascadeType;
 import javax.persistence.Entity;
 import javax.persistence.FetchType;
 import javax.persistence.GeneratedValue;
@@ -63,7 +64,7 @@
       this.dateOfBirth = dateOfBirth;
    }
    
-   @OneToMany(fetch = FetchType.LAZY, mappedBy = "person")
+   @OneToMany(fetch = FetchType.LAZY, mappedBy = "person", cascade = CascadeType.ALL)
    public Collection<Address> getAddresses()
    {
       return addresses;

Modified: modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/PersonAction.java
===================================================================
--- modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/PersonAction.java	2010-01-07 07:39:41 UTC (rev 11923)
+++ modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/PersonAction.java	2010-01-07 09:04:32 UTC (rev 11924)
@@ -1,6 +1,7 @@
 package org.jboss.seam.remoting.examples.model;
 
 import java.io.Serializable;
+import java.util.ArrayList;
 
 import javax.enterprise.context.Conversation;
 import javax.enterprise.context.ConversationScoped;
@@ -24,6 +25,7 @@
    {
       conversation.begin();
       person = new Person();
+      person.setAddresses(new ArrayList<Address>());
    }
    
    @WebRemote

Modified: modules/remoting/trunk/examples/model/src/main/webapp/model.html
===================================================================
--- modules/remoting/trunk/examples/model/src/main/webapp/model.html	2010-01-07 07:39:41 UTC (rev 11923)
+++ modules/remoting/trunk/examples/model/src/main/webapp/model.html	2010-01-07 09:04:32 UTC (rev 11924)
@@ -23,12 +23,15 @@
         
     var model = null;        
     
+    // Clears all the child elements of the specified element
     function clearElement(e) {
       while (e.hasChildNodes()) {
         e.removeChild(e.firstChild);
       }      
     }
     
+    // Creates an anchor element inside a div with the specified text
+    // and optional onclick event
     function createLinkRow(text, onclick) {
       var link = document.createElement("a");
       link.href = "#";
@@ -39,6 +42,7 @@
       return div;      
     }
     
+    // Loads the full list of People entities via a remoting call
     function loadPeople() {
       var personList = document.getElementById("personList");
       
@@ -58,8 +62,18 @@
     function getElementValue(elementName) {
       var value = document.getElementById(elementName).value;
       return (value.trim().length > 0) ? value : null; 
-    }    
+    }   
     
+    function createPerson() {
+      var action = new Seam.Action()
+        .setBeanType("org.jboss.seam.remoting.examples.model.PersonAction")
+        .setMethod("createPerson");
+      
+      model = new Seam.Model();
+      model.addBeanProperty("person", "org.jboss.seam.remoting.examples.model.PersonAction", "person");
+      model.fetch(action, fetchCallback);      
+    } 
+        
     function editPerson(personId) {
       var action = new Seam.Action()
         .setBeanType("org.jboss.seam.remoting.examples.model.PersonAction")
@@ -75,11 +89,13 @@
       var person = model.getValue("person");
       document.getElementById("firstName").value = person.getFirstName();
       document.getElementById("lastName").value = person.getLastName();
-      document.getElementById("dob").value = person.getDateOfBirth();
+      document.getElementById("dob").value = person.getDateOfBirth().toLocaleString();
       
       var addressDiv = document.getElementById("addresses");
       clearElement(addressDiv);      
       addressDiv.appendChild(createLinkRow("Load addresses", "loadAddresses()"));
+      
+      document.getElementById("personDetail").style.display = "block";
     }
     
     function loadAddresses() {
@@ -136,12 +152,23 @@
     }
     
     function apply() {
+      var person = model.getValue("person");
+      person.firstName = document.getElementById("firstName").value;
+      person.lastName = document.getElementById("lastName").value;
+      person.dateOfBirth = new Date(document.getElementById("dob").value);
+      
       var action = new Seam.Action()
         .setBeanType("org.jboss.seam.remoting.examples.model.PersonAction")
         .setMethod("savePerson");
-      model.applyUpdates(action);
+      model.applyUpdates(action, applyCallback);
     }
     
+    function applyCallback() {
+      loadPeople();       
+      alert("Changes applied");
+      document.getElementById("personDetail").style.display = "none";
+    }
+    
     function createDeleteAddressLink(address, div) {
       var link = document.createElement("a");
       link.href = "#";
@@ -191,16 +218,16 @@
   </script>   
   
   <div class="listContainer">
-    <div class="sectionHeader">People</div>
+    <div class="sectionHeader">People - click to edit</div>
     
     <div id="personList"></div>
     
     <div>
-      <a href="#" onclick="javascript:alert('new person')">Create new person</a>
+      <a href="#" onclick="createPerson()">Create new person</a>
     </div>
   </div>
   
-  <div class="personDetail">
+  <div id="personDetail" style="display:none">
     <div class="sectionHeader">Details</div>
     
     <div class="formRow">

Modified: modules/remoting/trunk/examples/model/src/main/webapp/style.css
===================================================================
--- modules/remoting/trunk/examples/model/src/main/webapp/style.css	2010-01-07 07:39:41 UTC (rev 11923)
+++ modules/remoting/trunk/examples/model/src/main/webapp/style.css	2010-01-07 09:04:32 UTC (rev 11924)
@@ -20,7 +20,7 @@
   font-weight: bold; 
 }
 
-div.personDetail {
+#personDetail {
   margin-left: 4px; 
   background-color: #eeeeee;
   float: left;



More information about the seam-commits mailing list