Re: [xwiki-users] get something with indexOf
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 users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
Re: [xwiki-users] get something with indexOf
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? Asiri Rathnayake wrote: > > Hi, > > On Thu, Dec 3, 2009 at 8:49 PM, Bubulina wrote: > >> >> #set($count = 0) >> #foreach ($d in $xwiki.sort($dateList)) >> >>$d >> $pageList.indexOf[$count] $pageList.indexOf[$count] >> >>delete >> >> >>#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 >> users@xwiki.org >> http://lists.xwiki.org/mailman/listinfo/users >> > ___ > users mailing list > users@xwiki.org > http://lists.xwiki.org/mailman/listinfo/users > > -- View this message in context: http://n2.nabble.com/get-something-with-indexOf-tp4106635p4107934.html Sent from the XWiki- Users mailing list archive at Nabble.com. ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
Re: [xwiki-users] get something with indexOf
Hi, On Thu, Dec 3, 2009 at 8:49 PM, Bubulina wrote: > > #set($count = 0) > #foreach ($d in $xwiki.sort($dateList)) > >$d > $pageList.indexOf[$count] $pageList.indexOf[$count] >delete > > >#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 > users@xwiki.org > http://lists.xwiki.org/mailman/listinfo/users > ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
[xwiki-users] get something with indexOf
#set($count = 0) #foreach ($d in $xwiki.sort($dateList)) $d $pageList.indexOf[$count] $pageList.indexOf[$count] delete #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? -- 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 users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users