You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Paul Davis <pa...@gmail.com> on 2008/08/07 18:50:02 UTC
array with single item iterates letters?
Hi,
I've got a form where there my be an arbitrary number of items.
However, I have a problem when there is only one item.
I've added the type hint
<input type="hidden" name="trackId@TypeHint" value="String[]" />
The type hint works when I get the json string. The value is correctly
wrapped in square brackets.
However, in my esp, it iterates the letters of the value (if there is only one)
<% for(var i=0; i <currentNode.trackId.length; i++) { %>
<div><%= currentNode.trackId[i] %></div>
<% } %>
I tried using the typeof(obj) operation in a test but, it returns
"object" regardless.
ideas?
thanks
Re: array with single item iterates letters?
Posted by Felix Meschberger <fm...@gmail.com>.
Hi,
Ok, thanks for the feedback. Then there might be something going wrong
with the ScriptableNode Wrapper. Created an issue for that [1]
Regards
Felix
[1] https://issues.apache.org/jira/browse/SLING-604
Paul Davis schrieb:
> Thanks for the response.
>
> The node is a special node type. I'm not sure about the property.
> I thought the "hint" would make it an array
> <input type="hidden" name="trackId@TypeHint" value="String[]" />
>
> I did manage to get it work with:
> var items = currentNode.getProperty("trackId").values;
> for( var i=0; i < items.length; i++ ) {
> .....
>
> I think the servlet is doing the right thing (using the hint) because
> getting the node as json shows the property as an array (even if only
> one item).
>
> On Thu, Aug 7, 2008 at 11:43 AM, Felix Meschberger <fm...@gmail.com> wrote:
>> Hi,
>>
>> Sounds like the ScriptableNode wrapper returns currentNode.trackId as a
>> single property instead of an array of properties. This single property is
>> then converted to a string and the characters iterated.
>>
>> Do you store the property in a node of a special node type or is it of type
>> nt:unstructured ? Can you tell me whether the property is mult-value:
>> currentNode.getProperty("trackId").definition.isMultiple() would return
>> true. Otherwise false is returned.
>>
>> The reason why I ask is to try and find out, whether your problem happens
>> upon storage in SlingPostServlet or up "read" in the ScriptableNode wrapper.
>>
>> Regards
>> Felix
>>
>>
>> Paul Davis schrieb:
>>> Hi,
>>>
>>> I've got a form where there my be an arbitrary number of items.
>>> However, I have a problem when there is only one item.
>>>
>>> I've added the type hint
>>> <input type="hidden" name="trackId@TypeHint" value="String[]" />
>>> The type hint works when I get the json string. The value is correctly
>>> wrapped in square brackets.
>>>
>>> However, in my esp, it iterates the letters of the value (if there is only
>>> one)
>>> <% for(var i=0; i <currentNode.trackId.length; i++) { %>
>>> <div><%= currentNode.trackId[i] %></div>
>>> <% } %>
>>>
>>> I tried using the typeof(obj) operation in a test but, it returns
>>> "object" regardless.
>>>
>>> ideas?
>>>
>>> thanks
>>>
>
Re: array with single item iterates letters?
Posted by Paul Davis <pa...@gmail.com>.
Thanks for the response.
The node is a special node type. I'm not sure about the property.
I thought the "hint" would make it an array
<input type="hidden" name="trackId@TypeHint" value="String[]" />
I did manage to get it work with:
var items = currentNode.getProperty("trackId").values;
for( var i=0; i < items.length; i++ ) {
.....
I think the servlet is doing the right thing (using the hint) because
getting the node as json shows the property as an array (even if only
one item).
On Thu, Aug 7, 2008 at 11:43 AM, Felix Meschberger <fm...@gmail.com> wrote:
> Hi,
>
> Sounds like the ScriptableNode wrapper returns currentNode.trackId as a
> single property instead of an array of properties. This single property is
> then converted to a string and the characters iterated.
>
> Do you store the property in a node of a special node type or is it of type
> nt:unstructured ? Can you tell me whether the property is mult-value:
> currentNode.getProperty("trackId").definition.isMultiple() would return
> true. Otherwise false is returned.
>
> The reason why I ask is to try and find out, whether your problem happens
> upon storage in SlingPostServlet or up "read" in the ScriptableNode wrapper.
>
> Regards
> Felix
>
>
> Paul Davis schrieb:
>>
>> Hi,
>>
>> I've got a form where there my be an arbitrary number of items.
>> However, I have a problem when there is only one item.
>>
>> I've added the type hint
>> <input type="hidden" name="trackId@TypeHint" value="String[]" />
>> The type hint works when I get the json string. The value is correctly
>> wrapped in square brackets.
>>
>> However, in my esp, it iterates the letters of the value (if there is only
>> one)
>> <% for(var i=0; i <currentNode.trackId.length; i++) { %>
>> <div><%= currentNode.trackId[i] %></div>
>> <% } %>
>>
>> I tried using the typeof(obj) operation in a test but, it returns
>> "object" regardless.
>>
>> ideas?
>>
>> thanks
>>
>
Re: array with single item iterates letters?
Posted by Felix Meschberger <fm...@gmail.com>.
Hi,
Sounds like the ScriptableNode wrapper returns currentNode.trackId as a
single property instead of an array of properties. This single property
is then converted to a string and the characters iterated.
Do you store the property in a node of a special node type or is it of
type nt:unstructured ? Can you tell me whether the property is
mult-value: currentNode.getProperty("trackId").definition.isMultiple()
would return true. Otherwise false is returned.
The reason why I ask is to try and find out, whether your problem
happens upon storage in SlingPostServlet or up "read" in the
ScriptableNode wrapper.
Regards
Felix
Paul Davis schrieb:
> Hi,
>
> I've got a form where there my be an arbitrary number of items.
> However, I have a problem when there is only one item.
>
> I've added the type hint
> <input type="hidden" name="trackId@TypeHint" value="String[]" />
> The type hint works when I get the json string. The value is correctly
> wrapped in square brackets.
>
> However, in my esp, it iterates the letters of the value (if there is only one)
> <% for(var i=0; i <currentNode.trackId.length; i++) { %>
> <div><%= currentNode.trackId[i] %></div>
> <% } %>
>
> I tried using the typeof(obj) operation in a test but, it returns
> "object" regardless.
>
> ideas?
>
> thanks
>