|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
checking if all variables are presentI have a template containing some variables to be rendered from context.
Is there way by which i can know if all the variables are present in the context, otherwise throw an error. |
|
|
Re: checking if all variables are presentMaybe this will help you This way I always test if variable is not null
.............
The #if directive in Velocity allows for text to be included when the web page is generated, on the conditional that the if statement is true. For example: #if( $foo ) <strong>Velocity!</strong> #end The variable $foo is evaluated to determine whether it is true, which will happen under one of two circumstances: (i) $foo is a boolean (true/false) which has a true value, or (ii) the value is not null. Remember that the Velocity context only contains Objects, so when we say 'boolean', it will be represented as a Boolean (the class). This is true even for methods that return ............ 2009/7/28 Captain Cid <captain_cid@...>
|
|
|
Re: checking if all variables are presentseveral possibilities:
a) You can use the experimental TemplateTool to programmatically get a list of references to check against the context before rendering: http://svn.apache.org/repos/asf/velocity/engine/trunk/experimental/templatetool/TemplateTool.java b) Use an buffering writer and a ReferenceInsertionEventHandler to stop rendering if something is missing c) Check with #if($!myvar != null) before using reference content (as in previous answer to this thread). Hope this helps somehow, Christoph Captain Cid wrote: > I have a template containing some variables to be rendered from context. > Is there way by which i can know if all the variables are present in the > context, otherwise throw an error. --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: checking if all variables are presentThe scenario for me is an email webservice
It has many templates each having certain variables. Email service picks us template and adds data provided to webservice. So it's kind of generic. I dont know how many variables are there in template. All variables given to web service will be used. But email should not be sent if any data is missing. So how to tackle such situation !
|
|
|
Re: checking if all variables are presentThanks
a) part worked well for me !
|
| Free embeddable forum powered by Nabble | Forum Help |