[TinyOWS-users] Problem inserting new features

Nicolas Ardissono nicolasardissono at yahoo.com.ar
Fri Dec 2 15:51:49 EST 2011


I had the same problem, and you have two options to solve it. Because is 
a field order problem.

Check with pgadmin how your fields are orderer, you have first name and 
then the_geom, so tinyows doesn't except anything after the_geom. What i 
do was delete the name field and create it again so it will be after 
the_geom as tinyows expect, with that it works for me.


Or you can try this script that supouse to order fields, but not always 
work:


/**
  * @requires OpenLayers/Strategy.js
  */

/**
  * Allow to force the ordering of attributes before saving
  *
  * @class
  */
OpenLayers.Strategy.SaveAttrOrder =
   OpenLayers.Class(OpenLayers.Strategy,
{

   /**
    * Order of attributes to save.
    *
    * Only the attributes listed here will be saved!
    *
    * @type {Array.<string>}
    */
   order: [],

   /**
    * Strategy to communicate with for save operation
    *
    * @type {OpenLayers.Strategy.Save}
    */
   saveStrategy: null,

   /**
    * APIMethod: activate
    * Activate the strategy.  Register any listeners, do appropriate setup.
    *
    * Returns:
    * {Boolean} The strategy was successfully activated.
    */
   activate: function() {
     var activated = OpenLayers.Strategy.prototype.activate.call(this);
     if (activated) {
       this.saveStrategy.events.on({
           start: this.beforeSave,
           scope: this
       });
     }
     return activated;
   },

   /**
    * APIMethod: deactivate
    * Deactivate the strategy.  Unregister any listeners, do appropriate
    *     tear-down.
    *
    * Returns:
    * {Boolean} The strategy was successfully deactivated.
    */
   deactivate: function() {
     var deactivated = OpenLayers.Strategy.prototype.deactivate.call(this);
     if(deactivated) {
       this.saveStrategy.events.un({
           start: this.beforeSave,
           scope: this
       });
     }
     return deactivated;
   },

   beforeSave: function(event) {
     var features = event.features;
     features.forEach(dojo.hitch(this, 'reorderFeature'));
   },

   reorderFeature: function(feature) {
     var obj = {};
     this.order.forEach(
         function(attr) {
           if (feature.attributes.hasOwnProperty(attr)) {
             obj[attr] = feature.attributes[attr];
           }
         });
     feature.attributes = obj;
   }




Hope this help

El 02/12/11 16:41, Jessica Lapointe escribió:
> Hello,
> I'm having trouble in inserting new features in my db. In fact I have
> the same problem as described in there:
> http://lists.maptools.org/pipermail/tinyows-users/2010-November/000230.html
> I use openlayers 2.11 and tinyows trunk revision 615.
>
> I'm able to update and delete data with no problem. If I insert simple
> features containing only geometry it also works. But if my new feature
> has data, my xml response in firebug will be "XML request isn't
> valid". Tinyows' log says :
>
> [Fri Dec  2 14:30:11 2011] [ERROR] Element '{http://127.0.0.1/}name':
> This element is not expected.
>
> [Fri Dec  2 14:30:11 2011] [ERROR] XML request isn't valid
>
> The xml sent to tinyows is the following:
>
> <wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" service="WFS"
> version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wfs
> http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <wfs:Insert>
> <feature:popplace xmlns:feature="http://127.0.0.1/">
> <feature:the_geom>
> <gml:Point xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
> <gml:coordinates decimal="." cs="," ts="
> ">-45.925780534744,-11.97656750679</gml:coordinates>
> </gml:Point>
> </feature:the_geom>
> <feature:name>test</feature:name>
> </feature:popplace>
> </wfs:Insert>
> </wfs:Transaction>
>
> Any help would be appreciated.
> _______________________________________________
> TinyOWS-users mailing list
> TinyOWS-users at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/tinyows-users
>
>    



More information about the TinyOWS-users mailing list