#9047 closed enhancement (fixed)
dojox.data.JsonRestStore support custom service for nested items
Reported by: | Jarrod Carlson | Owned by: | Kris Zyp |
---|---|---|---|
Priority: | high | Milestone: | 1.4 |
Component: | DojoX Data | Version: | 1.3.0 |
Keywords: | dojox rpc jsonrest jsonreststore | Cc: | |
Blocked By: | Blocking: |
Description
I have a REST service that provides for nested resources, e.g.:
/foos/123 /foos/123/bar
Because dojox.rpc.Rest insists on appending a trailing slash to the target path (#8980), I have provided my JsonRestStore? a custom service object.
However, after setting values on the nested "bar" item of /foos/123 and calling store.save(), there is a problem. dojox.rpc.JsonRest#getServiceAndId? attempts to locate a service for the id of the dirty object. Normally, it isn't a problem, but in this case, the "path" of the bar item being saved is "/foos/123/" with an id of "bar". In this case, JsonRest? determines that a service object is unavailable and proceeds to create one.
The problem is that JsonRest? is hard-coded to create an instance of dojox.rpc.Rest, and not the custom service object I had provided, which is perfectly capable of handling the PUT.
In order to solve this, I've modified the JsonRestStore? and JsonRest? classes to work with a "generator" class, which defaults to dojox.rpc.Rest. This way, when a JsonRestStore? is created, it can be provided a service generator instead of a service, and any subsequently created service objects will also be created by the same generator.
This probably isn't the "ideal" solution, but it does work. Please see the attached patches.
Alternatively, the getServiceAndId method could be modified to support nested matches. For example, if I already have a service for "/foos/" and I request the service for "/foos/123/bar", then the existing "/foos" service should be returned, rather than creating a new service.
Attachments (3)
Change History (7)
Changed 12 years ago by
Attachment: | dojox.rpc.JsonRest.js.diff added |
---|
Changed 12 years ago by
Attachment: | dojox.data.JsonRestStore.js.diff added |
---|
dojox.data.JsonRestStore?
comment:1 Changed 12 years ago by
The attached "alternative solitution" in 9047.diff is considerably less invasive of a change. In this alternate version, we configure the JsonRest? class with a default constructor for a service object, which can be overridden by user code. It also changes the getServiceAndId method to allow partial matches on a service path, thus allowing nested resources to be handled by the parent service.
Finally, in JsonRestStore?, the _getStoreForItem method is modified to try finding an existing service and use the attached store and creating a new store only as a last resort.
comment:2 Changed 12 years ago by
Owner: | changed from Jared Jurkiewicz to Kris Zyp |
---|
comment:3 Changed 12 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:4 Changed 12 years ago by
Milestone: | tbd → 1.4 |
---|
dojox.rpc.JsonRest?