get something with indexOf

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

get something with indexOf

                                                 
        #set($count = $count +1)

#end

just want to get the something from a list on the possition $count.
Please tell me what i am doing that wrong?
Bubulina
//date list is populated
#set($count = 0)
#foreach ($d in $xwiki.sort($dateList))
         
$d <a href="$pageList.indexOf[$count]">$pageList.indexOf[$count]  delete
Reply | Threaded
Open this post in threaded view
|

Re: get something with indexOf

Asiri Rathnayake
Hi,

On Thu, Dec 3, 2009 at 8:49 PM, Bubulina <[hidden email]> wrote:

>
> #set($count = 0)
> #foreach ($d in $xwiki.sort($dateList))
>         <tr>
>                <td>$d </td>
>            <td> $pageList.indexOf[$count] $pageList.indexOf[$count]   </td>
>            <td>delete</td>
>         </tr>
>
>        #set($count = $count +1)
>
> #end
>
> just want to get the something from a list on the possition $count.
> Please tell me what i am doing that wrong?
>

Is $pageList a java.util.List instance? If so you should do
$pageList.get($count) instead.

- Asiri


>
> --
> View this message in context:
> http://n2.nabble.com/get-something-with-indexOf-tp4106635p4106635.html
> Sent from the XWiki- Users mailing list archive at Nabble.com.
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: get something with indexOf

Sergiu Dumitriu-2
On 12/03/2009 07:42 PM, Bubulina wrote:
>
> evening,
> out of curiosity, is it possible to make something, to write a line of code
> without the "#set(" but to not show the result on the page?
> for instance:
> - if i #set($list = $util.arrayList)
> and then
>   $list.add($x) -just add x to the list, but in the same time shows "true"
> printed on the page. i would like to avoid this, and still keep the logic?

Velocity is just a wrapper for Real Java Code. $list is a java list, and
if you look at the API, you'll see that add returns a boolean. Velocity
is not smart, it does not classify methods in things that should print
something and things that only do stuff on the inside, so the result is
not important. Thus, calling any method that returns something other
than null will always result in printing the result. Here, calling means
simple calling, outside #if or #set or other directives.

Inside directives like #set and #if and macro calls, the result is not
printed, but used as a member of the directive. The trick for your
usecase is to do something like:

#set($discard = $list.add($x))

$discard is the generic variable name that we use inside XWiki code
especially for this kind of scenarios.

--
Sergiu Dumitriu
http://purl.org/net/sergiu/
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users