velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Barbara Baughman <baugh...@utdallas.edu>
Subject Getting no space after an ending directive
Date Fri, 06 Sep 2002 16:57:03 GMT
I was trying to output something after an #if statement that would not
have a space, but it looks like Velocity will not recognize an #end or
#else unless there is a space after it.

department=#if ($dept)$dept#elsenull#end

ctx.put("dept","something);

department=something#elsenull

I would like
department=something


If the value of $dept was not set, I would like the output
department=null

Instead the output is
department=


This happens with velocity-1.3.1-rc2 and velocity-1.3-rc1, and I have
no specially defined directive called #elsenull.  Is there any special way
to delimit the end of #end or #else that makes this work the way I wish?

Thanks

Barbara Baughman
X2157

On Fri, 6 Sep 2002, Cort Schaefer wrote:

> In the case that you proposed, you could also base it on whether you are on
> the first element or not, ie:
> 
> #foreach($o in $list)#if($velocityCount>1).#end$o#end
> 
> 
> 
> -----Original Message-----
> From: Jason Weinstein [mailto:JWeinstein@SeeBeyond.com] 
> Sent: Thursday, September 05, 2002 8:50 PM
> To: 'Velocity Users List'
> Subject: Is there a way to tell when iterating in #foreach if you have com e
> to the last element.
> 
> Is there a way to tell when iterating in #foreach if you have come to the
> last element.
> 
> Maybe the velocity team can plug in a  
> $hasNext = true|false
> as it already maintains a loop $velocityCount variable.
> 
> Use (Java code):
> 
> System.out.println(evaluate("#foreach ($obj in
> ${this.breadthFirstEnumeration()})${obj.userObject}.#end", root)));
> 
> Note in this case root is javax.swing.tree.DefaultMutableTreeNode
> 
> Want to plug in #if($hasNext).#end
> 
> I want to be able to delimit the list with a '.'
> 
> Printing something like "root.a.b.c" instead of "root.a.b.c."
> 
> Code (Java code):
> 
> Generic toString method (applys Object to template)
> 
> Thinking useful for testcases where you assert things based on internal
> values. Such as construct tree and assert evaluate(...).equals("root.a.b.c")
> 
> public static String evaluate(String template, Object obj) {
>     String retval = null;
>     try {
>         Velocity.init();
>         VelocityContext context = new VelocityContext();
>         context.put("this", obj);
>         StringWriter out = new StringWriter();
>         boolean bRet = Velocity.evaluate(context, out, "test", template);
>         if (bRet) {
>             retval = out.toString();
>         }
>         else {
>             retval = (obj == null) ? null: obj.toString();
>         }
>     }
>     catch (Exception e) {
>         e.printStackTrace();
>     }
>     return retval;
> }
> 
> This seems like an easy feature to add can someone forward this request to
> the right place. Thanks
> 
> --
> To unsubscribe, e-mail:
> <mailto:velocity-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:velocity-user-help@jakarta.apache.org>
> 
> --
> To unsubscribe, e-mail:
> <mailto:velocity-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:velocity-user-help@jakarta.apache.org>
> 
> --
> To unsubscribe, e-mail:
> <mailto:velocity-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:velocity-user-help@jakarta.apache.org>
> 


--
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