Author: shane.bryzak(a)jboss.com
Date: 2010-01-07 02:39:07 -0500 (Thu, 07 Jan 2010)
New Revision: 11922
Modified:
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:
fixed collection processing for model apply update requests
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 2010-01-07
07:31:16 UTC (rev 11921)
+++
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java 2010-01-07
07:39:07 UTC (rev 11922)
@@ -6,6 +6,7 @@
import java.io.StringReader;
import java.lang.reflect.Array;
import java.lang.reflect.Type;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -20,7 +21,6 @@
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.jboss.seam.remoting.Call;
-import org.jboss.seam.remoting.CallContext;
import org.jboss.seam.remoting.MarshalUtils;
import org.jboss.seam.remoting.RequestContext;
import org.jboss.seam.remoting.RequestHandler;
@@ -226,15 +226,21 @@
{
model.getCallContext().getInRefs().put("" + i,
model.getCallContext().getOutRefs().get(i));
}
+
+ List<Wrapper> newRefs = new ArrayList<Wrapper>();
- CallContext ctx = new CallContext(beanManager);
-
Element refsElement = modelElement.element("refs");
for (Element ref : (List<Element>) refsElement.elements("ref"))
{
- ctx.createWrapperFromElement(ref);
+ newRefs.add(model.getCallContext().createWrapperFromElement(ref));
}
+ // Unmarshal any new ref values
+ for (Wrapper w : newRefs)
+ {
+ w.unmarshal();
+ }
+
Element delta = modelElement.element("delta");
if (delta != null)
{
@@ -421,7 +427,14 @@
for (int i = 0; i < sourceList.size(); i++)
{
- targetList.set(i, sourceList.get(i));
+ if (targetList.size() < i + 1)
+ {
+ targetList.add(i, sourceList.get(i));
+ }
+ else if (targetList.get(i) != sourceList.get(i))
+ {
+ targetList.set(i, sourceList.get(i));
+ }
}
return true;
}
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 2010-01-07
07:31:16 UTC (rev 11921)
+++ modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js 2010-01-07
07:39:07 UTC (rev 11922)
@@ -908,12 +908,13 @@
return null;
};
- Seam.Delta.prototype.buildRefs = function() {
- var refs = [];
+ Seam.Delta.prototype.getNewRefs = function() {
+ var nr = [];
for (var i=0; i<this.refs.elements.length; i++) {
- if (this.refs.elements[i].value) refs.push(this.refs.elements[i]);
+ var key = this.refs.elements[i].key;
+ if (Seam.getBeanType(key) && this.model.getRefId(key) == -1) nr.push(key);
}
- return refs;
+ return nr;
};
};
@@ -1047,8 +1048,11 @@
Seam.Model.prototype.createApplyRequest = function(a, delta, cb) {
var callId = "" + Seam.__callId++;
+ var refs = [];
+ for (var i=0; i<this.workingRefs.length; i++) {
+ refs[i] = this.workingRefs[i];
+ }
var d = "<model id=\"" + this.id + "\"
operation=\"apply\">";
- var refs = delta.buildRefs();
if (a) {
d += "<action>";
if (a.beanType) {
@@ -1071,13 +1075,13 @@
for (var i=0; i<delta.refs.elements.length; i++) {
var k = delta.refs.elements[i].key;
var v = delta.refs.elements[i].value;
- var refId = this.getRefId(k);
if (v) {
+ var refId = this.getRefId(k);
d += "<changeset refid=\"" + refId + "\">";
if (v instanceof Seam.Changeset) {
for (var j=0; j<v.propertyChange.elements.length; j++) {
d += "<member name=\"" + v.propertyChange.elements[j].key +
"\">";
- d += Seam.serializeValue(v.propertyChange.elements[j].value, null,
this.workingRefs);
+ d += Seam.serializeValue(v.propertyChange.elements[j].value, null, refs);
d += "</member>";
}
} else {
@@ -1087,13 +1091,18 @@
}
}
d += "</delta>";
- if (refs.length > 0) {
+ var newRefs = delta.getNewRefs();
+ if (newRefs.length > 0) {
d += "<refs>";
- var idx = this.workingRefs.length;
- for (var i=0; i<refs.length; i++) {
- if (this.getRefId(refs[i]) != -1) {
- d += "<ref id=\"" + ++idx + "\">" +
Seam.serializeType(refs[i], refs) + "</ref>";
+ for (var i=0; i<newRefs.length; i++) {
+ var idx = refs.length;
+ for (var j=0; j<refs.length; j++) {
+ if (refs[j] == newRefs[i]) {
+ idx = j;
+ break;
+ }
}
+ d += "<ref id=\"" + idx + "\">" +
Seam.serializeType(newRefs[i], refs) + "</ref>";
}
d += "</refs>";
}
Show replies by date