4 Replies Latest reply on May 17, 2013 1:10 PM by Evert-Jan

    velocity version



      I seem to be running into a limitation in the velocity version 1.4 that comes w/JHS. I'm trying to do a recursive loop w/a macro that has a parameter and I receive the following error msg:

      Velocity log [error] VM #NVL_AND_EXPRESSION: error : too few arguments to macro. Wanted 1 got 0

      I found a bug online and it said it was fixed in a later velocity release:


      Can I easily upgrade the velocity version we're using w/o any significant issues? Is it as easy as replacing the velocity jar file?

      Thanks in advance,

      Edited by: p.mon on Mar 24, 2010 9:26 AM
        • 1. Re: velocity version
          Steven Davelaar-Oracle

          Yes, in theory that should be all.
          Never tried it though.

          Steven Davelaar,
          Jheadstart Team.
          • 2. Re: velocity version
            fyi tried it out and everything generated fine. however, upgrading the velocity version did not resolve the recursive loop problem.

            • 3. Re: velocity version
              Steven Davelaar-Oracle

              I think you get that error when you invoke a macro that is not yet defined. In case of a recursive call, that's always the case. I had a similar issue and solved it with a 'shell" macro and a recursive "body" macro:

              #macro (RECURSIVE_BODY_MACRO $page)
              ## do something

              #macro (SHELL_MACRO $page)
              ## process detail page components
              #foreach($pageComponent in ${page.pageComponents})
              #RECURSIVE_BODY_MACRO($page $page)

              Steven Davelaar,
              JHeadstart Team.
              • 4. Re: velocity version
                I know this is an old topic, but it is still relevant and I found a better solution.The example of Steven works, but only in a specific case. If the 'body' needs to call itself again (in true recursion) it no longer works.

                Anyway, the error in Velocity can actually simply be ignored; although it complains about the arguments it cannot find, it will generate just fine. If you combine that with the ability to overrule templates, it becomes really easy.

                The solution then looks as follows:

                #macro (FOO $bar)
                ## DO NOTHING, DUMMY FUNCTION

                #macro (FOO $bar)
                $do some coding here
                #foreach( $monkey in $bar.children )

                So we can simply define the same function first as a dummy function, and then overrule it with the real body. The velocity compiler no longer complains, but at runtime the dummy function will never be executed as the body is already overruled.