You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by wu qi <wq...@yahoo.com> on 2003/02/10 07:08:09 UTC

velocity tool subproject(VelocityViewServlet): How to configure the

      For the example provided with the source of VelocityViewServlet ,the is a parameter of toolbox in web.xml,and the value of tooltox is /WEB-INF/toolbox.xml.

      My question is what is this parameter and its funcionality,and how to configure toolbox.xml,I search all the document for this project ,but just dissapoint that no such information.Please help me!



---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now

Re: Useful addition to #foreach

Posted by Daniel Dekany <dd...@freemail.hu>.
Monday, February 10, 2003, 10:43:17 PM, Marvin Greenberg wrote:

> #foreach already has $velocityCount.  Add $isFirst and $isLast.  Simple to
> write a macro for this...
> Just add (somewhere)
> #set ($isLast = $velocityCount.equals( $arg3.size() ) )
> #set ($isFirst = $velocityCount.equals( 1 ) )
>
> #foreach ($obj in $List)
>    #if ($isFirst) <table> #end
>     <tr><td>$obj.Attribute</td></tr>
>    #if ($isLast) </table> #end
> #end

In the concrete situation above maybe it is better practice to do
something like this (sorry if my Vel. syntax is bad... I didn't used
Vel. for a year or so...):

#if (!$obj.isEmpty())
  <table>
  #foreach ($obj in $List)
    <tr><td>$obj.Attribute</td></tr>
  #end
  </table>
#end

but in the case of Vel. it has the big problem that the template will
not work if $obj is not a Collection Java object. The same problem with
$arg3.size() in isLast macro...

But anyway, something like $velocityIsLast in a template language is
definitely useful. It often happens that you want to know if you are in
the last loop or not. Say, if you want to put coma after all items,
except after the last item.

-- 
Best regards,
 Daniel Dekany



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


Re: Useful addition to #foreach

Posted by Bill Burton <bi...@progress.com>.
Hello,

Marvin Greenberg wrote:
> #foreach already has $velocityCount.  Add $isFirst and $isLast.  Simple to
> write a macro for this...
> Just add (somewhere)
> #set ($isLast = $velocityCount.equals( $arg3.size() ) )
> #set ($isFirst = $velocityCount.equals( 1 ) )
> 
> #foreach ($obj in $List)
>    #if ($isFirst) <table> #end
>     <tr><td>$obj.Attribute</td></tr>
>    #if ($isLast) </table> #end
> #end
> 
> to the foreach definition.
> 
> Note that there is a problem with global variables like these (including
> velocityCount) when loops are nested, and there is no obvious solution.
> Maybe allow a kludgy index by the loop variable name...

You can always just save the value in each outer loop:
     #foreach ($obj in $List)
         #set($outerCount = $velocityCount)
         #foreach ($item in $obj)
     ...

> 
> $velocityCount.of("obj") or $isFirst.for("obj")...
> 
> Better would be $obj.count(), $obj.isFirst() but that would require
> dynamically generating a specialization of whatever class $obj happens to be
> at each assignment (since you want $obj to behave like the kind of object
> the designer expects).  Hardly worth the complexity.

The best answer is an iterator wrapper tool.  This avoids global variables 
and can provide ways to start or end the iteration, get the index, 
determine if last iteration in the loop, etc., etc.   It happens someone 
has already written such a tool called FisherMill.  It was supposed to be 
comitted to the tools subproject but somehow that never happened.   You 
can grab it at 
http://marc.theaimsgroup.com/?l=velocity-user&m=103176242630349&w=2.

-Bill


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


Useful addition to #foreach

Posted by Marvin Greenberg <mg...@dctd.saic.com>.
#foreach already has $velocityCount.  Add $isFirst and $isLast.  Simple to
write a macro for this...
Just add (somewhere)
#set ($isLast = $velocityCount.equals( $arg3.size() ) )
#set ($isFirst = $velocityCount.equals( 1 ) )

#foreach ($obj in $List)
   #if ($isFirst) <table> #end
    <tr><td>$obj.Attribute</td></tr>
   #if ($isLast) </table> #end
#end

to the foreach definition.

Note that there is a problem with global variables like these (including
velocityCount) when loops are nested, and there is no obvious solution.
Maybe allow a kludgy index by the loop variable name...

$velocityCount.of("obj") or $isFirst.for("obj")...

Better would be $obj.count(), $obj.isFirst() but that would require
dynamically generating a specialization of whatever class $obj happens to be
at each assignment (since you want $obj to behave like the kind of object
the designer expects).  Hardly worth the complexity.


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


Re: velocity tool subproject(VelocityViewServlet): How to configure the

Posted by Nathan Bubna <na...@esha.com>.
wu qi said:
>       For the example provided with the source of VelocityViewServlet ,the
is a parameter of toolbox in web.xml,and the value of tooltox is
/WEB-INF/toolbox.xml.
>
>       My question is what is this parameter and its funcionality,and how
to configure toolbox.xml,I search all the document for this project ,but
just dissapoint that no such information.Please help me!

This parameter specifies the location of your toolbox configuration file.

The javadocs is where much of the useful documentation currently exists for
this project.  With regard to configuring the toolbox, you'll particularly
want look at the javadoc for the ServletToolboxManager.

Also, there are these links:

http://crufty.happysearch.com/velocity/tools/docs/
http://www.teamup.com/jakarta-velocity-tools/docs/index.html

Oh, and the better examples for using this project are the ones in the
velocity-struts library.  The example in the velocity-view library is pretty
trivial.

Nathan Bubna
nathan@esha.com


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