You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Jack Holt <ja...@gmail.com> on 2005/06/01 21:08:30 UTC

No conditional #stop? / Validating that a parameter was passed in code

Correct me if I am wrong, but it appears that #stop is not intended to
be used conditionally.

I saw this behavior when trying to write the following macro:

#macro(test $p $n)
	#if($!p == "")
		$n is required
                #stop
	#end
#end

#test($var "var")

I tried the above code in VeloGUI and noticed that velocity throws a
ParseErrorException with a message of Encountered "EOF" at line 4,
column 17

Am I right about this and (on a separate subject) is there a better
way to validate that a parameter was passed to a Velocity template

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


Re: No conditional #stop? / Validating that a parameter was passed in code

Posted by j&h systems <jh...@gmail.com>.
Hi, 

There were debates for #stop in former emails in this mailing list.
Bottom line I guess is #stop is not to be used.

You can search using the keyword "#stop" in my velocity mailing list
archive http://www.jhsystems.net and find relevant answers.

Cheers,

Jian

On 6/1/05, Jack Holt <ja...@gmail.com> wrote:
> Correct me if I am wrong, but it appears that #stop is not intended to
> be used conditionally.
> 
> I saw this behavior when trying to write the following macro:
> 
> #macro(test $p $n)
>         #if($!p == "")
>                 $n is required
>                 #stop
>         #end
> #end
> 
> #test($var "var")
> 
> I tried the above code in VeloGUI and noticed that velocity throws a
> ParseErrorException with a message of Encountered "EOF" at line 4,
> column 17
> 
> Am I right about this and (on a separate subject) is there a better
> way to validate that a parameter was passed to a Velocity template
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
>

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


Re: No conditional #stop? / Validating that a parameter was passed in code

Posted by Will Glass-Husain <wg...@forio.com>.
This is fixed in source code.  Eventually to be released in version 1.5.  In 
the meantime, you can use the nightly snapshot.

http://cvs.apache.org/snapshots/velocity/

WILL

----- Original Message ----- 
From: "Jack Holt" <ja...@gmail.com>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Wednesday, June 01, 2005 12:08 PM
Subject: No conditional #stop? / Validating that a parameter was passed in 
code


Correct me if I am wrong, but it appears that #stop is not intended to
be used conditionally.

I saw this behavior when trying to write the following macro:

#macro(test $p $n)
#if($!p == "")
$n is required
                #stop
#end
#end

#test($var "var")

I tried the above code in VeloGUI and noticed that velocity throws a
ParseErrorException with a message of Encountered "EOF" at line 4,
column 17

Am I right about this and (on a separate subject) is there a better
way to validate that a parameter was passed to a Velocity template

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


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


Re: No conditional #stop? / Validating that a parameter was passed in code

Posted by Will Glass-Husain <wg...@forio.com>.
Just to make sure this is clear,

We've implemented a patch and uploaded it to source code that has the 
behavior Jack expects.  In the meantime the behavior is really not very 
useful.

Eventually this will get released.  Or, if you need it now, use the latest 
(unreleased source code).

Best,
WILL

----- Original Message ----- 
From: "Simon Christian" <si...@stoutstick.com>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Wednesday, June 01, 2005 1:26 PM
Subject: Re: No conditional #stop? / Validating that a parameter was passed 
in code


> Hi Jack,
>
> You're dead right that it's not intended for that kind of use, it 
> actually terminates the execution of the template engine:
>
>   http://jakarta.apache.org/velocity/user-guide.html#Stop
>
> The easy way to test if a 'parameter' is in the context is simply:
>
>   #if( $var )
>
> or to test the opposite:
>
>   #if( ! $var )
>
> If you wanted to include it in a macro similar to your original one, 
> something like the following might be appropriate:
>
> #macro( test $var $varName )
>  #if( ! $var )
>   $varName is required!
>  #end
> #end
>
> - simon
>
>
> On 1 Jun 2005, at 20:08, Jack Holt wrote:
>
>
>> Correct me if I am wrong, but it appears that #stop is not intended to
>> be used conditionally.
>>
>> I saw this behavior when trying to write the following macro:
>>
>> #macro(test $p $n)
>>     #if($!p == "")
>>         $n is required
>>                 #stop
>>     #end
>> #end
>>
>> #test($var "var")
>>
>> I tried the above code in VeloGUI and noticed that velocity throws a
>> ParseErrorException with a message of Encountered "EOF" at line 4,
>> column 17
>>
>> Am I right about this and (on a separate subject) is there a better
>> way to validate that a parameter was passed to a Velocity template
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 


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


Re: No conditional #stop? / Validating that a parameter was passed in code

Posted by Simon Christian <si...@stoutstick.com>.
Hi Jack,

You're dead right that it's not intended for that kind of use, it  
actually terminates the execution of the template engine:

   http://jakarta.apache.org/velocity/user-guide.html#Stop

The easy way to test if a 'parameter' is in the context is simply:

   #if( $var )

or to test the opposite:

   #if( ! $var )

If you wanted to include it in a macro similar to your original one,  
something like the following might be appropriate:

#macro( test $var $varName )
  #if( ! $var )
   $varName is required!
  #end
#end

- simon


On 1 Jun 2005, at 20:08, Jack Holt wrote:


> Correct me if I am wrong, but it appears that #stop is not intended to
> be used conditionally.
>
> I saw this behavior when trying to write the following macro:
>
> #macro(test $p $n)
>     #if($!p == "")
>         $n is required
>                 #stop
>     #end
> #end
>
> #test($var "var")
>
> I tried the above code in VeloGUI and noticed that velocity throws a
> ParseErrorException with a message of Encountered "EOF" at line 4,
> column 17
>
> Am I right about this and (on a separate subject) is there a better
> way to validate that a parameter was passed to a Velocity template
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>



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