retrieving list in ftl from specified index

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

retrieving list in ftl from specified index

nashrul
I have this ftl snippet code.

<#assign seq = ["winter", "spring", "summer", "autumn"]>
<#list seq as x>
     --htmll code here
     --retrieviing seq here from certain index
</#list> 

How can i retrieve just the certain index from seq list (say x[0] and x[1]) ??
Reply | Threaded
Open this post in threaded view
|

Re: retrieving list in ftl from specified index

cjhowe
hmm..IIRC correctly, try ${seq[0]}  x is the current object in the
index.
--- nashrul <[hidden email]> wrote:

>
> I have this ftl snippet code.
>
> <#assign seq = ["winter", "spring", "summer", "autumn"]>
> <#list seq as x>
>      --htmll code here
>      --retrieviing seq here from certain index
> </#list>
>
> How can i retrieve just the certain index from seq list (say x[0] and
> x[1])
> ??
> --
> View this message in context:
>
http://www.nabble.com/retrieving-list-in-ftl-from-specified-index-tf4323738.html#a12312945
> Sent from the OFBiz - User mailing list archive at Nabble.com.
>
>

Reply | Threaded
Open this post in threaded view
|

Re: retrieving list in ftl from specified index

nashrul
thanks for your advice ghove.. but i try to apply this, and it doesn't work ....

cjhowe wrote
hmm..IIRC correctly, try ${seq[0]}  x is the current object in the
index.
--- nashrul <anas_aviv@yahoo.com> wrote:

>
> I have this ftl snippet code.
>
> <#assign seq = ["winter", "spring", "summer", "autumn"]>
> <#list seq as x>
>      --htmll code here
>      --retrieviing seq here from certain index
> </#list> 
>
> How can i retrieve just the certain index from seq list (say x[0] and
> x[1])
> ??
> --
> View this message in context:
>
http://www.nabble.com/retrieving-list-in-ftl-from-specified-index-tf4323738.html#a12312945
> Sent from the OFBiz - User mailing list archive at Nabble.com.
>
>
Reply | Threaded
Open this post in threaded view
|

Re: retrieving list in ftl from specified index

Jacques Le Roux
Administrator
Comparing x_index into the loop should do the trick

http://fmpp.sourceforge.net/freemarker/ref_directive_list.html

Jacques

De : "nashrul" <[hidden email]>

>
> thanks for your advice ghove.. but i try to apply this, and it doesn't work
> ....
>
>
> cjhowe wrote:
> >
> > hmm..IIRC correctly, try ${seq[0]}  x is the current object in the
> > index.
> > --- nashrul <[hidden email]> wrote:
> >
> >>
> >> I have this ftl snippet code.
> >>
> >> <#assign seq = ["winter", "spring", "summer", "autumn"]>
> >> <#list seq as x>
> >>      --htmll code here
> >>      --retrieviing seq here from certain index
> >> </#list>
> >>
> >> How can i retrieve just the certain index from seq list (say x[0] and
> >> x[1])
> >> ??
> >> --
> >> View this message in context:
> >>
> > http://www.nabble.com/retrieving-list-in-ftl-from-specified-index-tf4323738.html#a12312945
> >> Sent from the OFBiz - User mailing list archive at Nabble.com.
> >>
> >>
> >
> >
> >
>
> --
> View this message in context: http://www.nabble.com/retrieving-list-in-ftl-from-specified-index-tf4323738.html#a12323519
> Sent from the OFBiz - User mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: retrieving list in ftl from specified index

cjhowe
In reply to this post by nashrul
I just confirmed it, it does.

To test, I edited party/webapp/partymgr/party/findparty.ftl

line 87 has the following:
<#list roleTypes as roleType>
  <option
value="${roleType.roleTypeId}">${roleType.get("description",locale)}</option>
</#list>

after the subsequent td endtag, I added...
<td>${roleTypes[0].get("description",locale)}</td>
and was givin the correct description in a third column on the main
page of the party application.(localhost/partymgr/conrol/main)

So in your example, ${seq[0]} will print the first hashmap of the
collection seq.  If you wanted to access a specific field of the
hashmap, you would use ${seq[0].myFieldOfInterest?if_exists}
--- nashrul <[hidden email]> wrote:

>
> thanks for your advice ghove.. but i try to apply this, and it
> doesn't work
> ....
>
>
> cjhowe wrote:
> >
> > hmm..IIRC correctly, try ${seq[0]}  x is the current object in the
> > index.
> > --- nashrul <[hidden email]> wrote:
> >
> >>
> >> I have this ftl snippet code.
> >>
> >> <#assign seq = ["winter", "spring", "summer", "autumn"]>
> >> <#list seq as x>
> >>      --htmll code here
> >>      --retrieviing seq here from certain index
> >> </#list>
> >>
> >> How can i retrieve just the certain index from seq list (say x[0]
> and
> >> x[1])
> >> ??
> >> --
> >> View this message in context:
> >>
> >
>
http://www.nabble.com/retrieving-list-in-ftl-from-specified-index-tf4323738.html#a12312945

> >> Sent from the OFBiz - User mailing list archive at Nabble.com.
> >>
> >>
> >
> >
> >
>
> --
> View this message in context:
>
http://www.nabble.com/retrieving-list-in-ftl-from-specified-index-tf4323738.html#a12323519
> Sent from the OFBiz - User mailing list archive at Nabble.com.
>
>

Reply | Threaded
Open this post in threaded view
|

Re: retrieving list in ftl from specified index

jonwimp
If you're worried about hitting a non-existent array member, do this:

${(seq[n].myFieldOfInterest)!"Not Found!"}

Note that braces ().

Jonathon

Chris Howe wrote:

> I just confirmed it, it does.
>
> To test, I edited party/webapp/partymgr/party/findparty.ftl
>
> line 87 has the following:
> <#list roleTypes as roleType>
>   <option
> value="${roleType.roleTypeId}">${roleType.get("description",locale)}</option>
> </#list>
>
> after the subsequent td endtag, I added...
> <td>${roleTypes[0].get("description",locale)}</td>
> and was givin the correct description in a third column on the main
> page of the party application.(localhost/partymgr/conrol/main)
>
> So in your example, ${seq[0]} will print the first hashmap of the
> collection seq.  If you wanted to access a specific field of the
> hashmap, you would use ${seq[0].myFieldOfInterest?if_exists}
> --- nashrul <[hidden email]> wrote:
>
>> thanks for your advice ghove.. but i try to apply this, and it
>> doesn't work
>> ....
>>
>>
>> cjhowe wrote:
>>> hmm..IIRC correctly, try ${seq[0]}  x is the current object in the
>>> index.
>>> --- nashrul <[hidden email]> wrote:
>>>
>>>> I have this ftl snippet code.
>>>>
>>>> <#assign seq = ["winter", "spring", "summer", "autumn"]>
>>>> <#list seq as x>
>>>>      --htmll code here
>>>>      --retrieviing seq here from certain index
>>>> </#list>
>>>>
>>>> How can i retrieve just the certain index from seq list (say x[0]
>> and
>>>> x[1])
>>>> ??
>>>> --
>>>> View this message in context:
>>>>
> http://www.nabble.com/retrieving-list-in-ftl-from-specified-index-tf4323738.html#a12312945
>>>> Sent from the OFBiz - User mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>>
>> --
>> View this message in context:
>>
> http://www.nabble.com/retrieving-list-in-ftl-from-specified-index-tf4323738.html#a12323519
>> Sent from the OFBiz - User mailing list archive at Nabble.com.
>>
>>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: retrieving list in ftl from specified index

> and was givin the correct description in a third column on the main
> page of the party application.(localhost/partymgr/conrol/main)
>
> So in your example, ${seq[0]} will print the first hashmap of the
> collection seq.  If you wanted to access a specific field of the
> hashmap, you would use ${seq[0].myFieldOfInterest?if_exists}
> --- nashrul <anas_aviv@yahoo.com> wrote:
>
>> thanks for your advice ghove.. but i try to apply this, and it
>> doesn't work
>> ....
>>
>>
>> cjhowe wrote:
>>> hmm..IIRC correctly, try ${seq[0]}  x is the current object in the
>>> index.
>>> --- nashrul <anas_aviv@yahoo.com> wrote:
>>>
>>>> I have this ftl snippet code.
>>>>
>>>> <#assign seq = ["winter", "spring", "summer", "autumn"]>
>>>> <#list seq as x>
>>>>      --htmll code here
>>>>      --retrieviing seq here from certain index
>>>> </#list> 
>>>>
>>>> How can i retrieve just the certain index from seq list (say x[0]
>> and
>>>> x[1])
>>>> ??
>>>> --
>>>> View this message in context:
>>>>
> http://www.nabble.com/retrieving-list-in-ftl-from-specified-index-tf4323738.html#a12312945
>>>> Sent from the OFBiz - User mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>>
>> --
>> View this message in context:
>>
> http://www.nabble.com/retrieving-list-in-ftl-from-specified-index-tf4323738.html#a12323519
>> Sent from the OFBiz - User mailing list archive at Nabble.com.
>>
>>
>
>
nashrul
Ok.. thanks....

jonwimp wrote
If you're worried about hitting a non-existent array member, do this:

${(seq[n].myFieldOfInterest)!"Not Found!"}

Note that braces ().

Jonathon

Chris Howe wrote:
> I just confirmed it, it does.
>
> To test, I edited party/webapp/partymgr/party/findparty.ftl
>
> line 87 has the following:
> <#list roleTypes as roleType>
>   <option
> value="${roleType.roleTypeId}">${roleType.get("description",locale)}</option>
> </#list>
>
> after the subsequent td endtag, I added...
>
${roleTypes[0].get("description",locale)}