[ 
https://issues.apache.org/jira/browse/SLING-883?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12681821#action_12681821
 ] 

Rory Douglas commented on SLING-883:
------------------------------------

Actually looking at this again, the issue with newItem() is actually improper 
use of dojo.data.Write API.  The docs for that API indicate the first argument 
is not an item, but just a keywordArgs object whose attributes are intended to 
be the attributes on the new item.

It's the store's responsibility to provide items, to validate that objects are 
items, and to provide callers with a list of attributes & attribute values 
given an item.  So the internal structure of a returned item is intended to be 
a blackbox to widgets & calling code & shouldn't be relied upon directly.

If you want to create a new item that's a copy of an existing item, you need to 
use the store getValues/getAttributes methods to copy all the values & 
attribute names off the source item into a simple object, and provide that to 
the newItem method.  So I think the code is correct in its current form.

> SlingNodeStore.newItem() adds item URI as property
> --------------------------------------------------
>
>                 Key: SLING-883
>                 URL: https://issues.apache.org/jira/browse/SLING-883
>             Project: Sling
>          Issue Type: Bug
>          Components: Extensions
>            Reporter: Andreas Hartmann
>            Priority: Minor
>
> SlingNodeStore.newItem() uses the passed item argument directly to create the 
> Sling resource. Since the item has a "uri" field, the corresponding "uri" 
> property of the Sling resource will be set. This causes an exception if the 
> JCR node type doesn't support this property.
> Maybe it makes sense to use a "content" field inside the item object to 
> provide the content:
>   store.newItem({
>     uri: "/foo/bar/baz",
>     content: {
>       "jcr:primaryType": "foo:bar"
>     }
>   });
> Index: src/main/resources/dojox/data/SlingNodeStore.js
> ===================================================================
> --- src/main/resources/dojox/data/SlingNodeStore.js   (revision 752029)
> +++ src/main/resources/dojox/data/SlingNodeStore.js   (working copy)
> @@ -638,7 +638,7 @@
>      
>      var xhr =  xhr = dojo.xhrPost({
>          url: item.uri,
> -        content: item,
> +        content: item.content,
>          load: function(response, ioargs) {
>            item.dirty = false;
>            console.log("onNew");

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to