Mailing List webobjects-dev@wocommunity.org Message #23
From: Don Lindsay <webobjects-dev@wocommunity.org>
Subject: ERRest PUT not functioning
Date: Wed, 3 Feb 2021 00:21:05 -0600
To: <webobjects-dev@wocommunity.org>
Hello;

I have a ERRest project. Everything seems to be working except for when I update an entity the updateAction never gets called.  I put breakpoints in the source code on createAction, updateAction, indexAction, showAction. The method that gets called for PUT is indexAction.  Am I doing something wrong with the code, I took a look at the example apps in Project Wonder and used them to create my boilerplate.
  
Thanks,

Don


The request from the developer tools in the browser:



How the data is being sent:

$.ajax({
url: '/cgi-bin/WebObjects/xxxxxx.woa/ra/TileV2',
type: ‘PUT',
data: workingObject,
dataType: 'json',
contentType: 'application/json',
success: function (data) {
comp._currentTile = data;
console.log(JSON.stringify(data))
bootbox.alert({
title: "Tile Save",
message: "Tile saved successfully",
centerVertical: true
});
comp.resetDirty();
comp.initialize(window.connectorsjson, window.tilejson);;
},
error: function (data) {
bootbox.alert({
title: "Tile Save",
message: "Saving the tile failed, please try again later",
centerVertical: true
});
}
});



TileV2Controller.java

public class TileV2Controller extends BaseRestController {

public TileV2Controller(WORequest request) {
super(request);
// TODO Auto-generated constructor stub
}

@Override
public WOActionResults createAction() throws Throwable {
TileV2 tilev2 = create(createInFilter());
editingContext().saveChanges();
return response(tilev2,outFilter());
}

public ERXKeyFilter createInFilter() {
return ERXKeyFilter.filterWithAttributes();
}

public ERXKeyFilter outFilter() {
ERXKeyFilter out = createInFilter();
return out;
}



/**
* Returns the value of the "tile" variable from the route.
* @return
*/
public TileV2 tilev2() {
TileV2 tilev2 = routeObjectForKey("tileV2");
tilev2.setTenant(((com.mozaic.app.Session)session()).getTenant());
return tilev2;
}

/**
* The query filter is used in indexAction to control what attributes and relationships
* you expose to qualifiers through query parameters
* @return
*/
public static ERXKeyFilter queryFilter() {
ERXKeyFilter filter = ERXKeyFilter.filterWithAllRecursive();
filter.includeAll();
return filter;
}

/**
* This showFilter is used by indexAction and showAction and says to return all attributes
* of an TileV2, and for the owner, include all of its attributes. 
*/
public static ERXKeyFilter showFilter() {
ERXKeyFilter filter = ERXKeyFilter.filterWithAttributes();
return filter;
}

/**
* The updateFilter is used by updateAction and createAction and says to allow updating any attributes of an
* TileV2.
* @return
*/
public static ERXKeyFilter updateFilter() {
ERXKeyFilter filter = ERXKeyFilter.filterWithAttributes();
return filter;
}

@Override
public WOActionResults updateAction() {
TileV2 tilev2 = tilev2();
update(tilev2, updateFilter());
editingContext().saveChanges();
return response(tilev2, showFilter());
}

@Override
public WOActionResults destroyAction() throws Throwable {
TileV2 tilev2 = tilev2();
tilev2.delete();
editingContext().saveChanges();
return response(tilev2, showFilter());
}

@Override
public WOActionResults newAction() throws Throwable {
TileV2 tilev2 = TileV2.createTileV2(editingContext(), "New Description", null, "New Tile",  ((com.mozaic.app.Session)session()).getTenant());
return response(tilev2, showFilter());
}

@Override
public WOActionResults showAction() {
return response(tilev2(), showFilter());
}

/**
* indexAction uses an ERXRestFetchSpecification, which optionally allows you to expose sorting, qualifying, and batching in query parameters 
*/
@Override
public WOActionResults indexAction() {
if (isSchemaRequest()) {
return schemaResponse(showFilter());
}
ERXRestFetchSpecification<TileV2> fetchSpec = new ERXRestFetchSpecification<>(TileV2.ENTITY_NAME, null, null, queryFilter(), TileV2.NAME.ascs(), 25);
return response(fetchSpec, showFilter());
}


}

Image
PastedGraphic-1.png
Subscribe (FEED) Subscribe (DIGEST) Subscribe (INDEX) Unsubscribe Mail to Listmaster