You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Felix Meschberger <fm...@gmail.com> on 2010/03/04 15:30:08 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 Alexander Klimetschek <ak...@day.com>.
On Thu, Mar 4, 2010 at 15:30, Felix Meschberger <fm...@gmail.com> wrote:
>  * 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" ];

+1

On Thu, Mar 4, 2010 at 15:58, Justin Edelson <ju...@gmail.com> wrote:
> I like this idea. I've been meaning to find/create something similar for
> Groovy. As long as you can continue to the use the formal JCR API, I
> don't see anything wrong with supporting informal language-specific idioms.

+1

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com

Re: Modifying multi-value property with Ecmascript

Posted by Justin Edelson <ju...@gmail.com>.
I like this idea. I've been meaning to find/create something similar for
Groovy. As long as you can continue to the use the formal JCR API, I
don't see anything wrong with supporting informal language-specific idioms.

Justin

On 3/4/10 9:30 AM, 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
>>>