[seam-commits] Seam SVN: r11809 - in modules/remoting/trunk: src/main/java/org/jboss/seam/remoting and 2 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Fri Dec 11 06:25:58 EST 2009


Author: shane.bryzak at jboss.com
Date: 2009-12-11 06:25:57 -0500 (Fri, 11 Dec 2009)
New Revision: 11809

Modified:
   modules/remoting/trunk/examples/model/src/main/webapp/model.html
   modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/MarshalUtils.java
   modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/Model.java
   modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java
   modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
Log:
got end to end model fetch request working... yay!


Modified: modules/remoting/trunk/examples/model/src/main/webapp/model.html
===================================================================
--- modules/remoting/trunk/examples/model/src/main/webapp/model.html	2009-12-11 04:03:15 UTC (rev 11808)
+++ modules/remoting/trunk/examples/model/src/main/webapp/model.html	2009-12-11 11:25:57 UTC (rev 11809)
@@ -21,12 +21,12 @@
     function loadCustomer() {
       var customerId = document.getElementById("customerId").value;
       
-      var model = new Seam.Remoting.Model();
+      var model = new Seam.Model();
 
       var callback = function(model) { alert(model.getValue("customer").getFirstName()); };
               
       model.addBean("customer", "org.jboss.seam.remoting.examples.model.CustomerAction", "customer");
-      model.fetch(new Seam.Remoting.Action()
+      model.fetch(new Seam.Action()
         .setBeanType("org.jboss.seam.remoting.examples.model.CustomerAction")
         .setMethod("editCustomer")
         .addParam(customerId), callback);

Modified: modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/MarshalUtils.java
===================================================================
--- modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/MarshalUtils.java	2009-12-11 04:03:15 UTC (rev 11808)
+++ modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/MarshalUtils.java	2009-12-11 11:25:57 UTC (rev 11809)
@@ -85,6 +85,13 @@
    {
       out.write(MODEL_TAG_OPEN_START);
       out.write(model.getId().getBytes());
+      
+      if (model.getCallId() != null)
+      {
+         out.write("\" callId=\"".getBytes());
+         out.write(model.getCallId().getBytes());
+      }
+      
       out.write(MODEL_TAG_OPEN_END);
       
       for (String alias : model.getBeanProperties().keySet())

Modified: modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/Model.java
===================================================================
--- modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/Model.java	2009-12-11 04:03:15 UTC (rev 11808)
+++ modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/Model.java	2009-12-11 11:25:57 UTC (rev 11809)
@@ -28,10 +28,13 @@
    
    private BeanManager beanManager;
    private String id;
+   private String callId;
    private CallContext callContext;
    
-   public class BeanProperty 
+   public class BeanProperty implements Serializable
    {
+      private static final long serialVersionUID = 540993772239615536L;
+      
       private Bean<?> bean;
       private String propertyName;
       private Object value;      
@@ -115,6 +118,16 @@
       beanProperties = new HashMap<String, BeanProperty>();
    }
    
+   public void setCallId(String callId)
+   {
+      this.callId = callId;
+   }
+   
+   public String getCallId()
+   {
+      return callId;
+   }
+   
    /**
     * Evaluate each of the model's bean properties, expressions, etc and
     * store the values in the BeanProperty map.

Modified: modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java
===================================================================
--- modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java	2009-12-11 04:03:15 UTC (rev 11808)
+++ modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java	2009-12-11 11:25:57 UTC (rev 11809)
@@ -4,8 +4,10 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.StringReader;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import javax.enterprise.context.Conversation;
@@ -94,6 +96,7 @@
          {
             Model model = registry.createModel();
             models.add(model);
+            model.setCallId(callId);           
             
             if (modelElement.elements("action").size() > 0)
             {

Modified: modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
===================================================================
--- modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js	2009-12-11 04:03:15 UTC (rev 11808)
+++ modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js	2009-12-11 11:25:57 UTC (rev 11809)
@@ -1,5 +1,5 @@
 var Seam = {
-  type: new Object(),
+  type: {},
   beans: new Array(),
   debug: false,
   debugWindow: null,
@@ -415,6 +415,7 @@
           }
           catch (ex) {
              try {
+               Seam.log(ex.message + " : " + ex.stack);
                // Try it the IE way first...
                var doc = new ActiveXObject("Microsoft.XMLDOM");
                doc.async = "false";
@@ -463,9 +464,16 @@
         Seam.context.setConversationId(context.getConversationId());
     }
   }
-  if (bodyNode) {
+  if (bodyNode) {    
     var n = Seam.Xml.childNode(bodyNode, "result");
     if (n) Seam.processResult(n, context);
+    var cn = Seam.Xml.childNodes(bodyNode, "model");
+    for (var i=0; i<cn.length; i++) {
+      var callId = cn[i].getAttribute("callId");
+      var call = Seam.pendingCalls.get(callId);
+      Seam.pendingCalls.remove(callId);
+      if (call.model) call.model.processFetchResponse(cn[i]);
+    }
   }
 }
 
@@ -501,7 +509,7 @@
   var cn = Seam.Xml.childNodes(refsNode, "ref");
   for (var i=0; i<cn.length; i++) {
     var refId = parseInt(cn[i].getAttribute("id"));
-    var valueNode = refNode.firstChild;
+    var valueNode = cn[i].firstChild;
     if (valueNode.tagName == "bean") {
       var name = valueNode.getAttribute("type");
       var obj = Seam.isBeanRegistered(name) ? Seam.createBean(name) : null;
@@ -673,7 +681,7 @@
     var r = this.createFetchRequest(action);
     var env = Seam.createEnvelope(Seam.createHeader(), r.data);
     Seam.pendingCalls.put(r.id, r);
-    Seam.sendAjaxRequest(env, Seam.PATH_MODEL, this.processFetchResponse, false);
+    Seam.sendAjaxRequest(env, Seam.PATH_MODEL, Seam.processResponse, false);
   }
 
   Seam.Model.prototype.createFetchRequest = function(a) { // a = action
@@ -727,62 +735,19 @@
       }
     }
     d += "</model>";
-    return {data: d, id: callId};
+    return {data:d, id:callId, model:this};
   }
 
-  Seam.Model.prototype.processFetchResponse = function(doc) {
-    var headerNode;
-    var bodyNode;
-    var inScope = typeof(Seam) == "undefined" ? false : true;
-    if (!inScope) return;
-    var context = new Seam.Context; 
-    if (doc.documentElement) {
-      for (var i=0; i<doc.documentElement.childNodes.length; i++) {
-        var node = doc.documentElement.childNodes.item(i);
-        if (node.tagName == "header")
-          headerNode = node;
-        else if (node.tagName == "body")
-          bodyNode = node;
-      }
-    }
-    if (headerNode) {
-      var contextNode;
-      for (var i=0; i<headerNode.childNodes.length; i++) {
-        var node = headerNode.childNodes.item(i);
-        if (node.tagName == "context") {
-          contextNode = node;
-          break;
-        }
-      }
-      if (contextNode && context) {
-        Seam.unmarshalContext(contextNode, context);
-        if (context.getConversationId() && Seam.context.getConversationId() == null)
-          Seam.context.setConversationId(context.getConversationId());
-      }
-    }
-    if (bodyNode) {
-      for (var i=0; i<bodyNode.childNodes.length; i++) {
-        var n = bodyNode.childNodes.item(i);
-        if (n.tagName == "model") {          
-          var valueNodes = new Array();
-          var refsNode = null;
-          for (var j=0; j<n.childNodes.length; j++) {
-            var cn = n.childNodes.item(j);
-            if (cn.tagName == "value")
-              valueNodes.push({node:cn.firstChild,alias:cn.getAttribute("alias")});
-            else if (cn.tagName == "refs")
-              refsNode = n.childNodes.item(j);
-          }
-          var refs = new Array();
-          if (refsNode) Seam.unmarshalRefs(refsNode, refs);
-          for (var j=0; j<valueNodes.length; j++) {
-            var value = Seam.unmarshalValue(valueNodes[j].node, refs);
-            this.values.push({alias:valueNodes[j].alias, value:value}); 
-          }
-        }
-      }
-    }
-    if (this.callback) callback(this);
+  Seam.Model.prototype.processFetchResponse = function(modelNode) {
+    var valueNodes = Seam.Xml.childNodes(modelNode, "value");
+    var refsNode = Seam.Xml.childNode(modelNode, "refs");
+    var refs = new Array();    
+    if (refsNode) Seam.unmarshalRefs(refsNode, refs);
+    for (var i=0; i<valueNodes.length; i++) {
+      var value = Seam.unmarshalValue(valueNodes[i].firstChild,refs);
+      this.values.push({alias:valueNodes[i].getAttribute("alias"),value:value}); 
+    }         
+    if (this.callback) this.callback(this);
   }
 
   Seam.Model.prototype.applyUpdates = function(action) {



More information about the seam-commits mailing list