You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by ar...@cornell.edu on 2003/01/18 04:01:46 UTC
1.3rc2 and recursion
I am using the latest available release (1.3rc2) and am being bitten
badly by the bug described here:
http://issues.apache.org/bugzilla/show_bug.cgi?id=13623
"Use of Velocimacro forward reference and/or recursion causes error messages"
error : too few arguments to macro.
Use of recursion is critical to me, as I use Velocity to render a tree
structure recursively, which would be very cumbersome to do with JSP or
straight servlets.
Is there a safe version of Velocity which implements recursion?
Aaron Hamid
Cornell University
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: 1.3rc2 and recursion
Posted by Ilkka Priha <ip...@surfeu.fi>.
With a little helper macro it is possible to call macros recursively. The code
below shows an example applicable for string and numeric parameters:
## Evaluates other macros.
#macro(eval $_macro)$_macro#end
## Calls itself recursively 10 times.
#macro(recursive $_level)
#if ($_level < 10)
<p>We are at level $_level.</p>
#set ($_level = $_level + 1)
#eval("#recursive($_level)")
#end
#end
#recursive(0)
Produces:
We are at level 0.
We are at level 1.
We are at level 2.
We are at level 3.
We are at level 4.
We are at level 5.
We are at level 6.
We are at level 7.
We are at level 8.
We are at level 9.
More complicated parameters to recursive macros must be global as they would be
converted to strings when passed through #eval():
## Appends items to a global array.
#macro(append)
#set ($_size = $_array.size())
#if (($_size < 10) && $_array.add("New Item $_size"))
#eval("#append()")
#end
#end
#set ($_array = [ "First item 0" ])
#append()
<p>Array size: $_array.size()</p>
Produces:
Array size: 10
-- Ilkka
arh14@cornell.edu wrote:
> I am using the latest available release (1.3rc2) and am being bitten
> badly by the bug described here:
>
> http://issues.apache.org/bugzilla/show_bug.cgi?id=13623
>
> "Use of Velocimacro forward reference and/or recursion causes error messages"
>
> error : too few arguments to macro.
>
> Use of recursion is critical to me, as I use Velocity to render a tree
> structure recursively, which would be very cumbersome to do with JSP or
> straight servlets.
>
> Is there a safe version of Velocity which implements recursion?
>
> Aaron Hamid
> Cornell University
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
> .
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: 1.3rc2 and recursion
Posted by Ilkka Priha <ip...@surfeu.fi>.
With a little helper macro it is possible to call macros recursively. The code
below shows an example applicable for string and numeric parameters:
## Evaluates other macros.
#macro(eval $_macro)$_macro#end
## Calls itself recursively 10 times.
#macro(recursive $_level)
#if ($_level < 10)
<p>We are at level $_level.</p>
#set ($_level = $_level + 1)
#eval("#recursive($_level)")
#end
#end
#recursive(0)
Produces:
We are at level 0.
We are at level 1.
We are at level 2.
We are at level 3.
We are at level 4.
We are at level 5.
We are at level 6.
We are at level 7.
We are at level 8.
We are at level 9.
More complicated parameters to recursive macros must be global as they would be
converted to strings when passed through #eval():
## Appends items to a global array.
#macro(append)
#set ($_size = $_array.size())
#if (($_size < 10) && $_array.add("New Item $_size"))
#eval("#append()")
#end
#end
#set ($_array = [ "First item 0" ])
#append()
<p>Array size: $_array.size()</p>
Produces:
Array size: 10
-- Ilkka
arh14@cornell.edu wrote:
> I am using the latest available release (1.3rc2) and am being bitten
> badly by the bug described here:
>
> http://issues.apache.org/bugzilla/show_bug.cgi?id=13623
>
> "Use of Velocimacro forward reference and/or recursion causes error messages"
>
> error : too few arguments to macro.
>
> Use of recursion is critical to me, as I use Velocity to render a tree
> structure recursively, which would be very cumbersome to do with JSP or
> straight servlets.
>
> Is there a safe version of Velocity which implements recursion?
>
> Aaron Hamid
> Cornell University
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
> .
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: 1.3rc2 and recursion
Posted by Daniel Rall <dl...@collab.net>.
On Fri, 17 Jan 2003 arh14@cornell.edu wrote:
>
> I am using the latest available release (1.3rc2) and am being bitten
> badly by the bug described here:
>
> http://issues.apache.org/bugzilla/show_bug.cgi?id=13623
>
> "Use of Velocimacro forward reference and/or recursion causes error messages"
>
> error : too few arguments to macro.
>
> Use of recursion is critical to me, as I use Velocity to render a tree
> structure recursively, which would be very cumbersome to do with JSP or
> straight servlets.
>
> Is there a safe version of Velocity which implements recursion?
Hi Aaron. Don't know of one off hand, but as a (possibly kludy) work
around, you could add a Java class to your Velocity context which does this
recursive call for you. Or, you could add a Velocity object to peform
rendering from within a small template, and have the template render itself
recursively.
Personally, I'd rather just be able to call Velocimacros recursively, but
haven't found time to make fixing this bug a priority.
- Dan
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: 1.3rc2 and recursion
Posted by Daniel Rall <dl...@collab.net>.
On Fri, 17 Jan 2003 arh14@cornell.edu wrote:
>
> I am using the latest available release (1.3rc2) and am being bitten
> badly by the bug described here:
>
> http://issues.apache.org/bugzilla/show_bug.cgi?id=13623
>
> "Use of Velocimacro forward reference and/or recursion causes error messages"
>
> error : too few arguments to macro.
>
> Use of recursion is critical to me, as I use Velocity to render a tree
> structure recursively, which would be very cumbersome to do with JSP or
> straight servlets.
>
> Is there a safe version of Velocity which implements recursion?
Hi Aaron. Don't know of one off hand, but as a (possibly kludy) work
around, you could add a Java class to your Velocity context which does this
recursive call for you. Or, you could add a Velocity object to peform
rendering from within a small template, and have the template render itself
recursively.
Personally, I'd rather just be able to call Velocimacros recursively, but
haven't found time to make fixing this bug a priority.
- Dan
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>