attribute name-value pairs not updating in applyEdits

1939
2
Jump to solution
10-08-2012 09:40 PM
Town_ofSnowflake
Occasional Contributor
When I applyEdits to the server, the location and subtype are properly transferred to a new record.  However, the attribute name-value pairs are not being updated.  I'm updating them using the put command.  Instead, the subtype's default attribute values are assigned to the new record. 

public void applyEdits(Geometry geometry, FeatureType subType, ArcGISFeatureLayer featureLayer) {        //create a graphic using the type     Graphic graphic = featureLayer.createFeatureWithType(subType, geometry);     Map<String, Object> attr = graphic.getAttributes();        attr.put("Number", count);        attr.put("ObserverID", userID);        attr.put("Behavior", behavior);               featureLayer.applyEdits(new Graphic[] {graphic}, null, null, new CallbackListener<FeatureEditResult[][]>() {                   public void onError(Throwable error) {        }        public void onCallback(FeatureEditResult[][] editResult) {                }          });     finish();   }



All the attributes I'm trying to update are strings.
0 Kudos
1 Solution

Accepted Solutions
LiLin1
by Esri Contributor
Esri Contributor
Melo,

First, Graphic objects are immutable, which means its state cannot change after construction. So, even though you change the attribute values, the Graphic object won't be modified. Second, featureLayer.createFeatureWithType(subType, geometry) will create a new feature based on the subtype. And all the attributes are set to default values defined for that subtype via template.

To do what you intended to do, add the following line before calling applyEdit.

Graphic newGraphic = new Graphic(geometry, graphic.getSymbol(), attr, graphic.getInfoTemplate());

This line create a new feature based on the existing geometry and updated attribute. Then pass this newGraphic to the applyEdit.

View solution in original post

0 Kudos
2 Replies
LiLin1
by Esri Contributor
Esri Contributor
Melo,

First, Graphic objects are immutable, which means its state cannot change after construction. So, even though you change the attribute values, the Graphic object won't be modified. Second, featureLayer.createFeatureWithType(subType, geometry) will create a new feature based on the subtype. And all the attributes are set to default values defined for that subtype via template.

To do what you intended to do, add the following line before calling applyEdit.

Graphic newGraphic = new Graphic(geometry, graphic.getSymbol(), attr, graphic.getInfoTemplate());

This line create a new feature based on the existing geometry and updated attribute. Then pass this newGraphic to the applyEdit.
0 Kudos
Town_ofSnowflake
Occasional Contributor
Wow, great.  Thank you so much. I didn't realize that graphics were immutable.
0 Kudos