You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by Felix Meschberger <fm...@gmail.com> on 2010/03/04 12:36:44 UTC

Re: Modifying multi-value property with Ecmascript

Hi

(from the user@ question):

Without further thinking, it might be interesting to extend the
JavaScript functionality as follows:

  * Have the JCR Property representation ScriptableProperty be an
    EcmaScript array, allowing indexed access to the values and allowing
    for EcmaScript Array API.

     Example: add a value to the property
        node.propName.push("new value");

    Critical here is that the ScriptableProperty would have to cope
    with the multi-value issues around this.

  * Allow for direct node assignment to set property values.

      Example: set a property to a new value (array possible)
         node.propName = "single value";
         node.anotherProp = [ "value1", "value2" ];

A final note, though: Adding support for such idioms clearly separates
the EcmaScript support from the API supported in (all) other languags.
Specifically it would support API not supported by the core JCR API.
This may be fine, but we have to be aware of it.

Regards
Felix


On 04.03.2010 11:05, Erik Buene wrote:
> Hi
> 
> What is the best way to modify a multi-value property using ecmascript (.esp
> files)?
> 
> Was expecting something like this to work:
> 
> var arr = node.property;
> arr.push("added value");
> node.property = arr;
> node.save();
> 
> And it doesn't produce errors, but the value does not seem to be modified in
> the repository.
> 
> The only way I have been able to do it is:
> 
> var arr = node.property;
> arr.push("added value");
> var valueMap =
> (resource.adaptTo(Packages.org.apache.sling.api.resource.PersistableValueMap));
> var stringArray = java.lang.reflect.Array.newInstance(java.lang.String,
> arr.length);
> for(var i =0; i<arr.length; i++) {
> stringArray[i] = new Packages.java.lang.String(arr[i]);
> }
> vm.put("property", stringArray);
> vm.save();
> 
> Surely, there must be a more practical way of doing this.
> 
> Best regards,
> Erik Buene
> 

Re: Modifying multi-value property with Ecmascript

Posted by Felix Meschberger <fm...@gmail.com>.
oh man ... another one of those mails sent to the wrong list.

Sorry and please ignore.

Regards
Felix

On 04.03.2010 12:36, Felix Meschberger wrote:
> Hi
> 
> (from the user@ question):
> 
> Without further thinking, it might be interesting to extend the
> JavaScript functionality as follows:
> 
>   * Have the JCR Property representation ScriptableProperty be an
>     EcmaScript array, allowing indexed access to the values and allowing
>     for EcmaScript Array API.
> 
>      Example: add a value to the property
>         node.propName.push("new value");
> 
>     Critical here is that the ScriptableProperty would have to cope
>     with the multi-value issues around this.
> 
>   * Allow for direct node assignment to set property values.
> 
>       Example: set a property to a new value (array possible)
>          node.propName = "single value";
>          node.anotherProp = [ "value1", "value2" ];
> 
> A final note, though: Adding support for such idioms clearly separates
> the EcmaScript support from the API supported in (all) other languags.
> Specifically it would support API not supported by the core JCR API.
> This may be fine, but we have to be aware of it.
> 
> Regards
> Felix
> 
> 
> On 04.03.2010 11:05, Erik Buene wrote:
>> Hi
>>
>> What is the best way to modify a multi-value property using ecmascript (.esp
>> files)?
>>
>> Was expecting something like this to work:
>>
>> var arr = node.property;
>> arr.push("added value");
>> node.property = arr;
>> node.save();
>>
>> And it doesn't produce errors, but the value does not seem to be modified in
>> the repository.
>>
>> The only way I have been able to do it is:
>>
>> var arr = node.property;
>> arr.push("added value");
>> var valueMap =
>> (resource.adaptTo(Packages.org.apache.sling.api.resource.PersistableValueMap));
>> var stringArray = java.lang.reflect.Array.newInstance(java.lang.String,
>> arr.length);
>> for(var i =0; i<arr.length; i++) {
>> stringArray[i] = new Packages.java.lang.String(arr[i]);
>> }
>> vm.put("property", stringArray);
>> vm.save();
>>
>> Surely, there must be a more practical way of doing this.
>>
>> Best regards,
>> Erik Buene
>>