0

Trying to update two fields of a shapefile using a WFS update service published from GeoServer 2.4.3 with OpenLayers 2.13.1. I have a JavaScript with all the OpenLayers fun and a HTML document with all the interface fun. Essentially the user clicks on an object and updates a form and then saves it.

Assuming its possible? It's probably really simple but I can't crack it. The fields do not update and in the demo requests the service times out.

Here is the code I am trying;

function saveHandler() {
newDim = document.getElementById("dimension").value;
var num = parseFloat(newDim);
var newDimRound = num.toFixed(3);
newMaterial = document.getElementById("MaterialDD").value;

var saveDetails = OpenLayers.Request.POST({
        url: '<url of wfs service>',
        username: '<username>',
        password: '<password>',
        data: '<wfs:Transaction service="WFS" version="1.1.0"\n' +
                        'xmlns:topp="http://www.openplans.org/topp"\n' +
                        'xmlns:ogc="http://www.opengis.net/ogc"\n' +
                        'xmlns:wfs="http://www.opengis.net/wfs">\n' +
                        '<wfs:Update typeName="Store:Layer">\n' +
                        '<wfs:Property>\n' +
                        '<wfs:Name>Field 1</wfs:Name>\n' +
                        '<wfs:Value>' + newDimRound + '</wfs:Value>\n' +
                        '<wfs:Name>Field 2</wfs:Name>\n' +
                        '<wfs:Value>' + newMaterial + '</wfs:Value>\n' +
                        '</wfs:Property>\n' +
                        '<ogc:PropertyIsEqualTo>\n' +
                        '<ogc:PropertyName>Spatial_ID</ogc:PropertyName>\n' +
                        '<ogc:Literal>' + getSpatial_ID + '</ogc:Literal>\n' +
                        '</ogc:PropertyIsEqualTo>\n' +
                        '</wfs:Update>\n' +
                        '</wfs:Transaction>\n',
        callback: handler
    }); // end of Post

    function handler(updateSQL) {
        alert("Details Saved!")
    } // end handler    
};

I have tried putting the fields in their own property sections and different orders to no avail.

2
  • What does the GeoServer log file say is the problem?
    – Ian Turton
    Mar 17, 2014 at 9:15
  • @iant thanks I worked it out, feel like a dunce! I needed to separate the two fields into two different properties. I thought I tried that initially and it didn't work but I obviously had another different error. It's all working now.
    – user21482
    Mar 17, 2014 at 22:24

1 Answer 1

0

Worked it out, feel like a dunce! I needed to separate each property into it's own distinct property within the xml, rather than combine it into one.

I had:

<property>
<name></name>
<value></value>
<name></name>
<value></value>
</property>

Needed to have:

<property>
<name></name>
<value></value>
</property>

<property>
<name></name>
<value></value>
</property>

Like so:

        data: '<wfs:Transaction service="WFS" version="1.1.0"\n' +
                        'xmlns:topp="http://www.openplans.org/topp"\n' +
                        'xmlns:ogc="http://www.opengis.net/ogc"\n' +
                        'xmlns:wfs="http://www.opengis.net/wfs">\n' +
                        '<wfs:Update typeName="Store:Layer">\n' +
                        '<wfs:Property>\n' +
                        '<wfs:Name>Field 1</wfs:Name>\n' +
                        '<wfs:Value>' + newDimRound + '</wfs:Value>\n' +
                        '</wfs:Property>\n' +
                        '<wfs:Property>\n' +
                        '<wfs:Name>Field 2</wfs:Name>\n' +
                        '<wfs:Value>' + newMaterial + '</wfs:Value>\n' +
                        '</wfs:Property>\n' +
                        '<wfs:Property>\n' +
                        '<wfs:Name>Field 3</wfs:Name>\n' +
                        '<wfs:Value>' + remarks + '</wfs:Value>\n' +
                        '</wfs:Property>\n' +
                        '<ogc:PropertyIsEqualTo>\n' +
                        '<ogc:PropertyName>Spatial_ID</ogc:PropertyName>\n' +
                        '<ogc:Literal>' + getSpatial_ID + '</ogc:Literal>\n' +
                        '</ogc:PropertyIsEqualTo>\n' +
                        '</wfs:Update>\n' +
                        '</wfs:Transaction>\n',

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.