1

I have followed the example to setup a WFS Transaction successfully:

http://dev.openlayers.org/examples/wfs-protocol-transactions.html

My environment is GeoServer 2.6.1/OpenLayers 2.12.1. I do get the 4 toolbar icons on the upper right hand corner. (draw, modify, delete, save). I used a layer that is connected to an oracle table in geoserver as the editable layer.

Now, when I click on the "save" button, it does not add a record to that table. Of course, I was not expecting it to because it does not even know what key value I want to put in (as customerid) when it creates a new record with feature data; nor does it know which record to update the geometry for it its an existing key value (customerid). The editable layer I created based on the above link is:

// Customers Editable VECTOR Layer
            var saveStrategy = new OpenLayers.Strategy.Save();

            customers = new OpenLayers.Layer.Vector("Customers", {
                strategies: [new OpenLayers.Strategy.BBOX(), saveStrategy],
                projection: new OpenLayers.Projection("EPSG:2236"),
                protocol: new OpenLayers.Protocol.WFS({
                    version: "1.1.0",
                    srsName: "EPSG:2236",
                    url: "http://server01:8085/geoserver/sf/wfs",
                    featurePrefix: "sf",
                    featureType: "customers",
                    featureNS: "http://a.org/layers01",
                    geometryName: "GEOMETRY"
                })
            });

The oracle table itself has the following fields:

-customerId
-geometry
-date_updated

How do I perform inserts through openlayers/geoserver/all the way to the oracle table? (To included key value and geometry, etc) I would like the above example to actually save the geometry back to a specific record in the table. I am not sure how to proceed on this.


I am able to do inserts! It creates a new customerId with correct geometry. However, it increments the primary key by one, but ignores the value I place in added_feature.attributes.customerId for a new customerId key. And, I cannot get it to update at all.

I did set the customerId in the FeatureAdded method and set the state to OpenLayers.State.UPDATE. I also checked that the customerId I placed in the added_feature.attributes.customerId variable does exist in the table. This is the error I get when I try an update:

java.lang.RuntimeException: Parsing failed for FeatureId:
java.lang.NullPointerException Parsing failed for FeatureId:
java.lang.NullPointerException
1

I haven't tried the combination of Geoserver and Oracle but I guess that the WFS-T should work out of the box like it does when I use PostGIS as Database.

First of all I think you should find out WHY your features are not stored (violated NOT NULL constraints, check-constraints or something like that). In your Geoserver WebUI you can doublecheck that in the "Services-->WFS"-section the service level is set to transactional or complete.

In your javascript you can register some events for your save-strategy to find out more when the save-strategy is triggered, when it fails and when it can save sucessfully:

var saveStrategy = new OpenLayers.Strategy.Save();


function showSuccessMsg(e){
 console.log("Transaction successfully completed");
 //console.log(e);

 }

 function showFailureMsg(e){
  alert(e.response.error.exceptionReport.exceptions[0].texts[0]);
 //console.log(e);
 }

function saveStart(event) {
        console.log('save layer start');
    }


 saveStrategy.events.register("success", '', showSuccessMsg);

 saveStrategy.events.register('start', null, saveStart);

 saveStrategy.events.register('fail', null, showFailureMsg);

Of course you should also have a look at your debug-tools (for example firebug to see in the console or the network tab what's happening) And last but not least you can look into the logfiles of your DBMS.

If you know why you can't save you can adapt your code so you can set the attributes you want to save. For inserting new Features you can for example register the featureadded-event to get the added feature and set its attributes:

    var draw = new OpenLayers.Control.DrawFeature(
            wfs, OpenLayers.Handler.Polygon,
            {
                title: "Draw Feature",
                displayClass: "olControlDrawFeaturePolygon",
                multi: true
            }
        );
     draw.events.register("featureadded",'' , FeatureAdded);

     function FeatureAdded(object){ 
           console.log('feature added');
      var added_feature = object.feature; 
            added_feature.state = OpenLayers.State.INSERT;  

            // static version should be replaced by user interaction
            added_feature.attributes.customerId = 42442;
        } 
map.addControl(draw);

If you have set the properties you need to set you can trigger the saveStrategy (whats done when you click the save-button)

 saveStrategy.save();

As next steps you can use more dynamic ways to assign the attributes (for example textfields and document.getElementById.innerHTML)

If all of this works fine you can use the modifyfeature-control to update geometry and attributes.If you update features don't forget to set the featurestate to OpenLayers.State.UPDATE

  • Thomas, thank you! See update #1 above, I made some progress. – Robert Smith Feb 25 '15 at 19:01
  • good to see the progress ;) Have you already tried if you can edit the wfs-service with QGIS-Desktop? Just to see if Geoserver/Oracle causes the problem or if the javascript has to be changed... – Thomas B Feb 26 '15 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.