You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Anagha <an...@gmail.com> on 2006/02/07 11:04:19 UTC

Disable echo in VTL

Hi,
I'm building the XML in the VTL.
At some point I retrieve the value of an element and set its text as
$elem.setText( $sometext )

#foreach($elem in $rootelem.getChildren())
    #set ($elemname = $elem.getName())
    #set( $sometext = $userprops.get($elemname)  )
    $elem.setText( $sometext )

#end

In the output I get each element printed as --- "[Element: <serviceName/>]"
where serviceName is the the element name.
This happens for all the elements in the for loop. I want to disable this
output on the console/file which comes from "setText"

I tried :
VelocityEngine ve = new VelocityEngine();
ve.setProperty(VelocityEngine.VM_MESSAGES_ON, "false");

But still the elements are printed which is not desired.
Also I get a lot of new lines in the output which I want to disable.

Any pointers?
--
Thanks & Regards,
Anagha

Re: Disable echo in VTL

Posted by ap...@recks.org.
I used a macro for this purpose

## ------------------------------------------------------------------------
## convenience directive to invoke a method and ignore the return value
## ------------------------------------------------------------------------
#macro( call $foo )#if($foo)#**##end#end
## the comment in the if-statement avoids an empty if-body parser error
...
       #call( $elem.setText( $sometext ) )

Beware... some people may argue that putting such code in templates
is "not the right place"(TM), if you desire to follow the MVC paradigm.

The newlines and whitespaces is something that needs adressing in velocity,
see the proposed solutions in the wiki:
   http://wiki.apache.org/jakarta-velocity/VelocityWhitespaceGobbling

Cheers,
Christoph

Anagha wrote:
> Hi,
> I'm building the XML in the VTL.
> At some point I retrieve the value of an element and set its text as
> $elem.setText( $sometext )
> 
> #foreach($elem in $rootelem.getChildren())
>     #set ($elemname = $elem.getName())
>     #set( $sometext = $userprops.get($elemname)  )
>     $elem.setText( $sometext )
> 
> #end
> 
> In the output I get each element printed as --- "[Element: <serviceName/>]"
> where serviceName is the the element name.
> This happens for all the elements in the for loop. I want to disable this
> output on the console/file which comes from "setText"
> 
> I tried :
> VelocityEngine ve = new VelocityEngine();
> ve.setProperty(VelocityEngine.VM_MESSAGES_ON, "false");
> 
> But still the elements are printed which is not desired.
> Also I get a lot of new lines in the output which I want to disable.
> 
> Any pointers?
> --
> Thanks & Regards,
> Anagha
> 



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


Re: Disable echo in VTL

Posted by Ravikanth L <ra...@gmail.com>.
Hi,
Use as below
#foreach($elem in $rootelem.getChildren())##
   #set ($elemname = $elem.getName())##
   #set( $sometext = $userprops.get($elemname)  )##
   #set($tempVariable = $elem.setText( $sometext ))##
#end##

to ignore the return value from setText, just pretend as assigning to a
variable ( its the way i used in my templates). If anyone has a better way
to ignore such unneccesary return values from printing, pls let me know.

For unnecessary new lines, in your for loop, there will be new lines each
after a statement. So if you put ## i.e comment as EOL, it will ignore those
new lines. There are lot of bugs reported for formatting and new lines in
velocity. Please go through the forum mails for further reference.

Regards,
Ravi

On 2/7/06, Anagha <an...@gmail.com> wrote:
>
> Hi,
> I'm building the XML in the VTL.
> At some point I retrieve the value of an element and set its text as
> $elem.setText( $sometext )
>
> #foreach($elem in $rootelem.getChildren())
>    #set ($elemname = $elem.getName())
>    #set( $sometext = $userprops.get($elemname)  )
>    $elem.setText( $sometext )
>
> #end
>
> In the output I get each element printed as --- "[Element:
> <serviceName/>]"
> where serviceName is the the element name.
> This happens for all the elements in the for loop. I want to disable this
> output on the console/file which comes from "setText"
>
> I tried :
> VelocityEngine ve = new VelocityEngine();
> ve.setProperty(VelocityEngine.VM_MESSAGES_ON, "false");
>
> But still the elements are printed which is not desired.
> Also I get a lot of new lines in the output which I want to disable.
>
> Any pointers?
> --
> Thanks & Regards,
> Anagha
>
>