You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by bren36 <tk...@gmail.com> on 2009/04/17 11:03:03 UTC

scripting return values from a called function

Hi

I have the following scenario 

  string retvlaue = Function (void)

How can i  script this inside velocity ????
-- 
View this message in context: http://www.nabble.com/scripting-return-values-from-a-called-function-tp23093915p23093915.html
Sent from the Velocity - Dev mailing list archive at Nabble.com.


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


Re: scripting return values from a called function

Posted by ap...@recks.org.
Hi,

your question is not clear. You seem to be familiar with some other programming or scripting language - please get up-to-date with Java for the application side, also look at the examples in the Velocity developers guide:
  http://velocity.apache.org/engine/releases/velocity-1.6.2/developer-guide.html
and Velocity syntax for the template side; read the Velocity users guide:
  http://velocity.apache.org/engine/releases/velocity-1.6.2/user-guide.html

If your function is part of a Java class, place an instance into the Velocity context either with the ToolboxManager or using Java code in your application before merging:
  context.put("Functions", new Function());
(more at: http://velocity.apache.org/engine/releases/velocity-1.6.2/developer-guide.html#How_Velocity_Works )
and use it in your template:
  #set( $retvalue = $Functions.function() )

If you want to define scripted code in your Velocity template (called macros), you can do:
  #macro( Function )
   ...do something wise
  #end
and use it in your template:
  #set( $retvalue = "#Function()" )
Please note that macros can only return strings! So if you need variant return types, you need a Java class with a corresponding method (in which case a "void" parameter does not make sense - how will it differentiate what to return?).

Hope this helped,
Christoph

bren36 wrote:
> Hi
> 
> I have the following scenario 
> 
>   string retvlaue = Function (void)

:I There are no void pass-in parameters in Java.

> 
> How can i  script this inside velocity ????


> -------- Original Message --------
> Subject: return value
> Date: Thu, 16 Apr 2009 12:14:12 -0700 (PDT)
> From: bren36 <tk...@gmail.com>
> Reply-To: Velocity Users List <us...@velocity.apache.org>
> To: user@velocity.apache.org
> 
> 
> Hi ,
> 
> Want to achieve the following using  vm get a return value from a  function
> - the return value can be a structure /integer /string  type .
> 
> eg .
> 
> temp FUNCTION_call ()
> 
> Anyone have any ideas how i can achieve  this in.vm ?


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