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

Julian Sedding commented on SLING-522:
--------------------------------------

Quote from JCR API PropertyDefinition.isMultiple(): "Note that the isMultiple 
flag is special in that a given node type may have two property definitions 
that are identical in every respect except for the their isMultiple status." 
(http://www.day.com/maven/jsr170/javadocs/jcr-1.0/javax/jcr/nodetype/PropertyDefinition.html#isMultiple())

This is also reflected by the fact, that there are variations of 
Node.setProperty(), for which the documentation states whether they are to be 
used for setting single-value properties or multi-value properties. E.g. 
setProperty(String name, Value value) for single-value properties and 
setProperty(String name, Value[] values).

If my interpretation of the JCR documentation is correct, it would be the 
responsibility of Sling to decide whether to set a single-value or a 
multi-value property.

A pseudo code implementation could look something like this:

POST Servlet receives a post request with prop1=value1 on the node at 
/content/node1

if nodetype of /content/node1 defines a property with the name prop1 {
    if definition of prop1 is single-value  {
        set-single-value /content/node1/prop1=value1
    } else { // multi-value
        set-multi-value /content/node1/prop1=[value1]
    }
} else {
    set property the way it is done currently
}

After writing this post,  I don't believe anymore that this issue is correctly 
classified as a bug. However, I still believe that the expected behavior would 
be, that if a property is defined by the nodetype, it should be used. I.e. if 
the post servlet receives a single value and the nodetype defines a multi-value 
property, the single value should assigned to the multi-value property, rather 
than creating a new single-value property.

> Default POST Servlet writes single-value property even though node type 
> mandates multi-value.
> ---------------------------------------------------------------------------------------------
>
>                 Key: SLING-522
>                 URL: https://issues.apache.org/jira/browse/SLING-522
>             Project: Sling
>          Issue Type: Bug
>          Components: Servlets Post
>    Affects Versions: 2.0.1
>            Reporter: Julian Sedding
>            Priority: Minor
>             Fix For: 2.0.1
>
>
> If a JCR node-type defines a multi-value property (e.g. String[]) and only a 
> single value for this property is posted, the property will become 
> single-value (e.g String). The POST Servlet should check, if the property is 
> multi-value and respect that. Otherwise, any code reading the property value 
> would need to check, whether it is multi-value or not and handle both cases.
> It might even be beneficial to force a multi-value property, if there is no 
> node-type that defines it. This would provide for better control of 
> unstructured data.

-- 
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