Proper handling of null and undefined attribute values in WFS transactions. r=ahocevar (closes #2222)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9615 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2009-08-07 22:35:55 +00:00
parent 5964a8db60
commit c1a0d405e4
2 changed files with 19 additions and 5 deletions

View File

@@ -254,9 +254,11 @@ OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
// add in attributes
for(var key in feature.attributes) {
this.writeNode(
"Property", {name: key, value: feature.attributes[key]}, node
);
if(feature.attributes[key] !== undefined) {
this.writeNode(
"Property", {name: key, value: feature.attributes[key]}, node
);
}
}
// add feature id filter
@@ -269,7 +271,9 @@ OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
"Property": function(obj) {
var node = this.createElementNSPlus("wfs:Property");
this.writeNode("Name", obj.name, node);
this.writeNode("Value", obj.value, node);
if(obj.value !== null) {
this.writeNode("Value", obj.value, node);
}
return node;
},
"Name": function(name) {

View File

@@ -27,11 +27,18 @@
var feature = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(1,2),
{foo: "bar"});
{foo: "bar"}
);
var insertFeature = feature.clone();
// null value does not show up in insert
insertFeature.attributes.nul = null;
insertFeature.state = OpenLayers.State.INSERT;
var updateFeature = feature.clone();
// undefined value means don't create a Property element
updateFeature.attributes.unwritten = undefined;
// null value gets Property element with no Value
updateFeature.attributes.nul = null;
updateFeature.fid = "fid.42";
updateFeature.state = OpenLayers.State.UPDATE;
var deleteFeature = feature.clone();
@@ -144,6 +151,9 @@
<wfs:Name>foo</wfs:Name>
<wfs:Value>bar</wfs:Value>
</wfs:Property>
<wfs:Property>
<wfs:Name>nul</wfs:Name>
</wfs:Property>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:FeatureId fid="fid.42"/>
</ogc:Filter>