[GIS] Problem with WFS-T save strategy in Openlayers

geoserveropenlayers-2wfswfs-twms

In my web map application, I have added the editable wfs vector layer for feature editing. But in save strategy method, Insert and Update Geometry is working fine.But Update Attributes is not saved in transaction. Did I miss anything to include while adding editable layer? Please suggest me to fix this problem.

var saveStrategy;
function init(){ 
format = 'image/png';

bounds = new OpenLayers.Bounds(
            -288161.9289062237, -435.65815425360597,
            949406.755566389, 1300000
        );
var options = {
controls: [],
maxExtent: bounds,
maxResolution: 5079.826789665053,
projection: "EPSG:404000",
units: 'm'
};

 osMap = new OpenLayers.Map('map', options);

//Setup Base layer
tiled = new OpenLayers.Layer.WMS(
            "Oxford_Map", "http://xxx.xx.x.xx:8080/geoserver/cite/wms",
            {
                LAYERS: 'Oxford_Map',
                STYLES: '',
                format: format,
                tiled: true,
                tilesOrigin: osMap.maxExtent.left + ',' + osMap.maxExtent.bottom
            },
            {                        
                buffer: 0,
                displayOutsideMaxExtent: true,
                isBaseLayer: true,
                yx: { 'EPSG:404000': false }
            }                  
        );

untiled = new OpenLayers.Layer.WMS(
            "Oxford_Map", "http://xxx.xx.x.xx:8080/geoserver/cite/wms",
            {
                LAYERS: 'Oxford_Map',
                STYLES: '',
                format: format
            },
            {                        
                singleTile: true,
                ratio: 1,
                isBaseLayer: true,
                yx: { 'EPSG:404000': false }
            }                    
        );

 osMap.addLayers([untiled, tiled]);

 //set up a save strategy
saveStrategy = new OpenLayers.Strategy.Save();
saveStrategy.events.register("success", '', ChangesSuccess);
saveStrategy.events.register("failure", '', ChangesFailed);

wfs = new OpenLayers.Layer.Vector("ODC_Private_Graphics_Data", {
    strategies: [new OpenLayers.Strategy.BBOX(), saveStrategy],     
    projection: 'EPSG:27700',
    protocol: new OpenLayers.Protocol.WFS({
        version: '1.1.0',
        url: 'http://xxx.xxx.x.xx:8080/geoserver/wfs',
        featurePrefix: 'cite',
        featureNS: 'http://www.opengeospatial.net/cite',                        
        featureType: 'ODC_Private_Graphics_Data', 
        geometryName: 'the_geom',           
        extractAttributes: true,
        srsName: 'EPSG:27700',
        isBaseLayer: false,
        visibility: true,
        schema: 'http://xxx.xxx.x.xx:8080/geoserver/wfs/DescribeFeatureType?version=1.1.0&;typename=cite:ODC_Private_Graphics_Data',
    });


osMap.addLayers([wfs]);
}

    //This function will be invoked when I click on save image in web map application 
 function saveFeature() { 
  for (var ss = 0; ss < wfs.selectedFeatures.length; ss++) {
      var selFeat = wfs.selectedFeatures[ss];

      selFeat.attributes.FeatureName = 'Test';
       selFeat.state = OpenLayers.State.UPDATE;
  }

  saveStrategy.save();
 }


function delFeature() {
if (wfs.selectedFeatures.length > 0) {
for (var dd = 0; dd < wfs.selectedFeatures.length; dd++) {
     var selFeat = wfs.selectedFeatures[dd];
     if (selFeat.fid == undefined) {
         this.wfs.destroyFeatures([selFeat]);
        } else {
        selFeat.state = OpenLayers.State.DELETE;
        this.wfs.events.triggerEvent("afterfeaturemodified", { feature: selFeat });
        selFeat.renderIntent = "select";
        this.wfs.drawFeature(selFeat);
        }
    }    
} 

 function ChangesSuccess() {
  alert('Done');
 }

 function ChangesFailed() {
  alert('Failed');
 }

Best Answer

Only clues here: difficult to help you when not easy to reproduce on my own

  • Did you set the proxy?
  • Using the OpenLayers call, did you try to debug the save part only on your server side (GeoServer)? You can do that by using a tool like Fiddler Windows only) or Charles (not free) You have to catch the call, replay it and make modifications. You can also use the Firefox or Google Chrome "Copy as CURL" functions (https://coderwall.com/p/-fdgoq) to do the same. You will be able to play on the featureNS or featurePrefix parameters. When your tests will be done on server side (and work), you will just have to make modifications in your OpenLayers code to make things work.