velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <ge...@optonline.net>
Subject Re: #foreach tool
Date Wed, 11 Sep 2002 11:47:03 GMT
On 9/11/02 5:05 AM, "Denis" <jido@respublica.fr> wrote:

> Oops, don't know why my javac let pass this one.
> I will fix this and add some javadoc today. Geir, do you think we
> put this tool in the Tools?
> 

Sounds reasonable - in the jakarta-velocity-tools project?

> Cheers,
> -- Denis.
> 
> On Wednesday, September 11, 2002, at 12:32  am, Ken Anderson wrote:
> 
>> "FisherMill.java": Error #: 300 : constructor
>> ArrayIterator(java.lang.Object) not found in class
>> org.apache.velocity.util.ArrayIterator at line 71, column 33
>> 
>> Ken
>> 
>> 
>> bredelet@mac.com wrote:
>>> Guys,
>>> I am writing a little tool that helps to write a #foreach that
>>> terminates after 10 entries or such things. The source needs to
>>> be documented but basically the functionality is here.
>>> It can wrap a list, a map, an iterator, a collection, an enumeration.
>>> To get the next element you call $tool.more(). If you don't call
>>> more(), the tool will terminate the #foreach. That means that you
>>> can set a condition that will stop the loop very easily.
>>> After that, you can reuse the tool to display the remaining
>>> elements. You need to do $tool.reset() to start over from the
>>> beginning.
>>> Use $tool.hasNext() to check if there are more elements.
>>> I called it FisherMill because it sounds funny, if we put it in
>>> the tools we could give it a better name :-)
>>> This is an example of use:
>>> Java
>>> ----
>>> context.put("mill",new FisherMill());
>>> VTL
>>> ---
>>> #set ($list = [1, 2, 3, 5, 8, 13])
>>> #set ($numbers = $mill.wrap($list))
>>> #foreach ($item in $numbers)
>>> #if ($item < 8) $numbers.more()#end
>>> #end
>>> $numbers.more()
>>> $numbers.reset()
>>> #foreach ($item in $numbers)
>>>    $numbers.more() + $numbers.more() = $numbers.more()
>>> #end
>>> Output
>>> ------
>>>  1 2 3 5
>>> 8
>>>    1 + 2 = 3
>>>    5 + 8 = 13
>>> Cheers,
>>> -- Denis.
> 
> 
> --
> To unsubscribe, e-mail:
> <mailto:velocity-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:velocity-user-help@jakarta.apache.org>
> 

-- 
Geir Magnusson Jr. 
Research & Development, Adeptra Inc.
geirm@adeptra.com
+1-203-247-1713



--
To unsubscribe, e-mail:   <mailto:velocity-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:velocity-user-help@jakarta.apache.org>


Mime
View raw message