velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Kienenberger <mkien...@alaska.net>
Subject Re: Conditional display - Approach question
Date Wed, 20 Oct 2004 14:10:08 GMT
Manish <prolist@gmx.net> wrote:
> (1) Put a conditional check in velocity template while iterating though a
> list to decide if the book should be displayed. It would be sth like this 
-
> 
> #foreach($book in booklist)
>     #if($StockManager.isAvailable($book.number))
>          ## do whatever here...
>     #end
>     ## don't display anything if book is not available
> #end
> 
> (2) Another approach is to check this in VARIOUS actions while creating 
the
> list itself if the book should be added to the list at all.
> 
> First approach sounds easier to implement, but it means that the view part
> is taking decision about business logic, which sounds "not so nice"
> Second approach is difficult because there are many actions that will have
> to be changed, besides there are many programmers working on various
> actions, so they all need to take care of that. So I am trying to avoid
> this.... However, there's one more advantage here, if I do it this way I 
can
> add a unit test to check that only "available" books are getting added.

If you want to be a purist, you probably need to decide if it's business 
logic or display logic.  Is there any chance you'll eventually want to 
display non-available books?

If you decide it's business logic, another option would be to forward 
everything to a filtering action which then forwards to your display action. 
 The "logic" would still be separate from the view logic, but you'd have 
chained them together in your config file.  This is probably how I'd do it.


> p.s. BTW, is there anything similar to Java "continue" in VTL?

If you're talking about #foreach loops, in standard velocity there's 
nothing.   There may-or-may-not be a #stop directive you can install as a 
patch in the bugzilla database, but I use an #if statement.

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


Mime
View raw message