You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Sam Joseph <ga...@yha.att.ne.jp> on 2002/12/21 09:43:41 UTC
java code in template screwing up ...
Hi,
I'm using Velocity 1.2 and I'm having a strange problem from some java
code in my velocity templates. Apologies for the longish mail, but I
wanted to try and specify excatly what was happening. Many thanks in
advance for reading this, and for any help you might be able to provide.
I'm trying to autogenerate some java classes, so naturally there is java
code in the velocity template. The template (or chunk of it) looks like
this:
****template****
private Hashtable $check_form_method_name(WebForm p_form)
throws Exception
{
SubmitButton x_submit_button = null;
Hashtable x_buttons = new Hashtable();
//type: hidden,submit,check,textbox
#foreach($input in $inputs)
// $input.getType() // $input.getName()
#end
return x_buttons;
}
****template****
if I run velocity with some data I get this output:
***output***
private Hashtable checkEditBookmarkCommandForm(WebForm p_form)
throws Exception
{
SubmitButton x_submit_button = null;
Hashtable x_buttons = new Hashtable();
//type: hidden,submit,check,textbox
// hidden // ACTION//
// hidden // URI//
// text // TITLE//
// submit // SUBMIT//
// checkbox // SHARE//
// text // KEYWORDS//
// checkbox // DELETE//
return x_buttons;
}
***output***
all is well and good, however when I try to actually put the java code I
want inside the foreach loop (even without integrating it with the
velocity variables) like so :
***template***
#foreach($input in $inputs)
assertTrue(p_form.isTextParameter()); // $input.getType() //
$input.getName()
#end
***template***
the output ends up stopping towards the end of the loop without
completing. No errors are thrown and there is nothing untowards in the
velocity log that is not also there when the template is fully parsed
and the output complete generated
***output***
private Hashtable checkEditBookmarkCommandForm(WebForm p_form)
throws Exception
{
SubmitButton x_submit_button = null;
Hashtable x_buttons = new Hashtable();
// should these tests be checking that other buttons etc aren't present ???
// FIXXXXXXXX
//type: hidden,submit,check,textbox
assertTrue(p_form.isTextParameter()); // hidden // ACTION
assertTrue(p_form.isTextParameter()); // hidden // URI
assertTrue(p_form.isTextParameter()); // text // TITLE
assertTrue(p_form.isTextParameter()); // submit // SUBMIT
assertTrue(p_form.isTextParameter()); // checkbox // SHARE
assertTrue(p_form.isTextParameter()); // text
***output***
Just for reference here is the velocity log:
Sat Dec 21 17:39:24 JST 2002 [debug] AvalonLogSystem initialized using
logfile D:\user\code\java\misc\httpunit-1.5\neurogrid\velocity.log
Sat Dec 21 17:39:24 JST 2002 [info] Jakarta Velocity v1.2
Sat Dec 21 17:39:24 JST 2002 [info] RuntimeInstance initializing.
Sat Dec 21 17:39:24 JST 2002 [info] Default Properties File:
org\apache\velocity\runtime\defaults\velocity.properties
Sat Dec 21 17:39:24 JST 2002 [info] Resource manager initializing.
Sat Dec 21 17:39:24 JST 2002 [info] Resource Loader Instantiated:
org.apache.velocity.runtime.resource.loader.FileResourceLoader
Sat Dec 21 17:39:24 JST 2002 [info] FileResourceLoader : initialization
starting.
Sat Dec 21 17:39:24 JST 2002 [info] FileResourceLoader : adding path
'templates'
Sat Dec 21 17:39:24 JST 2002 [info] FileResourceLoader : adding path
'templates/support'
Sat Dec 21 17:39:24 JST 2002 [info] FileResourceLoader : adding path
'templates/test'
Sat Dec 21 17:39:24 JST 2002 [info] FileResourceLoader : initialization
complete.
Sat Dec 21 17:39:24 JST 2002 [info] Loaded Pluggable Directive:
org.apache.velocity.runtime.directive.Literal
Sat Dec 21 17:39:24 JST 2002 [info] Loaded Pluggable Directive:
org.apache.velocity.runtime.directive.Macro
Sat Dec 21 17:39:24 JST 2002 [info] Loaded Pluggable Directive:
org.apache.velocity.runtime.directive.Parse
Sat Dec 21 17:39:24 JST 2002 [info] Loaded Pluggable Directive:
org.apache.velocity.runtime.directive.Include
Sat Dec 21 17:39:24 JST 2002 [info] Loaded Pluggable Directive:
org.apache.velocity.runtime.directive.Foreach
Sat Dec 21 17:39:24 JST 2002 [info] Created: 20 parsers.
Sat Dec 21 17:39:24 JST 2002 [info] Velocimacro : initialization starting.
Sat Dec 21 17:39:24 JST 2002 [info] Velocimacro : adding VMs from VM
library template : VM_global_library.vm
Sat Dec 21 17:39:24 JST 2002 [info] Velocimacro : added new VM :
#quietnull( a ) : source = VM_global_library.vm
Sat Dec 21 17:39:25 JST 2002 [info] Velocimacro : added new VM :
#recurse( a ) : source = VM_global_library.vm
Sat Dec 21 17:39:25 JST 2002 [info] Velocimacro : added new VM :
#callrecurse( ) : source = VM_global_library.vm
Sat Dec 21 17:39:25 JST 2002 [info] Velocimacro : added new VM :
#testbool( b ) : source = VM_global_library.vm
Sat Dec 21 17:39:25 JST 2002 [error] VM #recurse: error : too few
arguments to macro. Wanted 1 got 0 -->
Sat Dec 21 17:39:25 JST 2002 [info] ResourceManager : found
VM_global_library.vm with loader
org.apache.velocity.runtime.resource.loader.FileResourceLoader
Sat Dec 21 17:39:25 JST 2002 [info] Velocimacro : VM library template
macro registration complete.
Sat Dec 21 17:39:25 JST 2002 [info] Velocimacro : allowInline = true :
VMs can be defined inline in templates
Sat Dec 21 17:39:25 JST 2002 [info] Velocimacro : allowInlineToOverride
= false : VMs defined inline may NOT replace previous VM definitions
Sat Dec 21 17:39:25 JST 2002 [info] Velocimacro : allowInlineLocal =
false : VMs defined inline will be global in scope if allowed.
Sat Dec 21 17:39:25 JST 2002 [info] Velocimacro : messages on : VM
system will output logging messages
Sat Dec 21 17:39:25 JST 2002 [info] Velocimacro : autoload off : VM
system will not automatically reload global library macros
Sat Dec 21 17:39:25 JST 2002 [info] Velocimacro : initialization complete.
Sat Dec 21 17:39:25 JST 2002 [info] Velocity successfully started.
Sat Dec 21 17:39:25 JST 2002 [info] ResourceManager : found
SupportCommand.vm with loader
org.apache.velocity.runtime.resource.loader.FileResourceLoader
Sat Dec 21 17:39:25 JST 2002 [info] ResourceManager : found
HttpUnitBaseTest.vm with loader
org.apache.velocity.runtime.resource.loader.FileResourceLoader
Thanks very much in advance.
CHEERS> SAM
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: java code in template screwing up ...
Posted by Sam Joseph <ga...@yha.att.ne.jp>.
didge wrote:
>Did you ever flush/close the the writers?
>
>
oops. (looks guilty)
Yes closing them makes things work.
Thanks for you help.
CHEERS> SAM
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: java code in template screwing up ...
Posted by "Geir Magnusson Jr." <ge...@adeptra.com>.
On Sunday, December 22, 2002, at 04:42 AM, didge wrote:
> Did you ever flush/close the the writers?
Oh - good one. Yes, that would do it.
--
Geir Magnusson Jr 203-355-2219(w)
Adeptra, Inc. 203-247-1713(m)
geirm@adeptra.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: java code in template screwing up ...
Posted by didge <di...@foundrylogic.com>.
Did you ever flush/close the the writers?
didge
> -----Original Message-----
> From: Sam Joseph [mailto:gaijin@yha.att.ne.jp]
> Sent: Saturday, December 21, 2002 9:28 PM
> To: Velocity Users List
> Subject: Re: java code in template screwing up ...
>
>
> Geir Magnusson Jr. wrote:
>
> > Wow. Wacky. Are you sure that the merge isn't throwing an exception?
>
> don't think it's throwing an exception, the code I'm using is this:
>
> try
> {
> String x_support_class_name = getSupportClassName(p_form_name);
> x_context.put("support_class_name",x_support_class_name);
>
> FileOutputStream x_f_out = new
> FileOutputStream(x_support_class_name + ".java");
> Writer x_writer = new BufferedWriter(new
> OutputStreamWriter(x_f_out,o_encoding));
>
> Velocity.mergeTemplate("SupportCommand.vm", o_encoding,
> x_context, x_writer);
>
> String x_test_class_name = getTestClassName(p_form_name);
> String x_check_form_method_name = "check" + x_support_class_name
> + "Form";
> x_context.put("test_class_name",x_test_class_name);
> x_context.put("check_form_method_name",x_check_form_method_name);
>
> x_f_out = new FileOutputStream(x_test_class_name+ ".java");
> x_writer = new BufferedWriter(new
> OutputStreamWriter(x_f_out,o_encoding));
>
> Velocity.mergeTemplate("HttpUnitBaseTest.vm", o_encoding,
> x_context, x_writer);
> }
> catch(Exception e){e.printStackTrace();}
>
> and I can't see a stack trace
>
> > Does it matter what you put in the loop?
>
> I just tried
>
> #foreach($input in $inputs)
> assertTrue(p_form); // $input.getType() // $input.getName()
> #end
>
> and I got:
>
>
> private Hashtable checkEditBookmarkCommandForm(WebForm p_form)
> throws Exception
> {
> SubmitButton x_submit_button = null;
> Hashtable x_buttons = new Hashtable();
>
> // should these tests be checking that other buttons etc aren't
> present ???
> // FIXXXXXXXX
> //type: hidden,submit,check,textbox
>
> assertTrue(p_form); // hidden // ACTION
> assertTrue(p_form); // hidden // URI
> assertTrue(p_form); // text // TITLE
> assertTrue(p_form); // submit // SUBMIT
> assertTrue(p_form); // checkbox // SHARE
> assertTrue(p_form); // text // KEYWORDS
> assertTrue(p_form); // checkbox // DELETE
>
> // so we have a questi
>
>
> so it seems to be stopping in a different place depending on what is in
> the loop.
>
> I'm using ant to run things and thinking that might have an effect I
> decided to switch running through the main method. The effect is the
> same. No exceptions, and depending on the loop contents different
> amounts of the final file being created.
>
> There is definitely something odd going on. I am going to have to strip
> this down and get something working, and then built back up from there.
> If you have any pointers from the information I provide above I will be
> most grateful.
>
> Thanks in advance.
>
> CHEERS> SAM
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: java code in template screwing up ...
Posted by Sam Joseph <ga...@yha.att.ne.jp>.
Geir Magnusson Jr. wrote:
> Wow. Wacky. Are you sure that the merge isn't throwing an exception?
don't think it's throwing an exception, the code I'm using is this:
try
{
String x_support_class_name = getSupportClassName(p_form_name);
x_context.put("support_class_name",x_support_class_name);
FileOutputStream x_f_out = new
FileOutputStream(x_support_class_name + ".java");
Writer x_writer = new BufferedWriter(new
OutputStreamWriter(x_f_out,o_encoding));
Velocity.mergeTemplate("SupportCommand.vm", o_encoding,
x_context, x_writer);
String x_test_class_name = getTestClassName(p_form_name);
String x_check_form_method_name = "check" + x_support_class_name
+ "Form";
x_context.put("test_class_name",x_test_class_name);
x_context.put("check_form_method_name",x_check_form_method_name);
x_f_out = new FileOutputStream(x_test_class_name+ ".java");
x_writer = new BufferedWriter(new
OutputStreamWriter(x_f_out,o_encoding));
Velocity.mergeTemplate("HttpUnitBaseTest.vm", o_encoding,
x_context, x_writer);
}
catch(Exception e){e.printStackTrace();}
and I can't see a stack trace
> Does it matter what you put in the loop?
I just tried
#foreach($input in $inputs)
assertTrue(p_form); // $input.getType() // $input.getName()
#end
and I got:
private Hashtable checkEditBookmarkCommandForm(WebForm p_form)
throws Exception
{
SubmitButton x_submit_button = null;
Hashtable x_buttons = new Hashtable();
// should these tests be checking that other buttons etc aren't
present ???
// FIXXXXXXXX
//type: hidden,submit,check,textbox
assertTrue(p_form); // hidden // ACTION
assertTrue(p_form); // hidden // URI
assertTrue(p_form); // text // TITLE
assertTrue(p_form); // submit // SUBMIT
assertTrue(p_form); // checkbox // SHARE
assertTrue(p_form); // text // KEYWORDS
assertTrue(p_form); // checkbox // DELETE
// so we have a questi
so it seems to be stopping in a different place depending on what is in
the loop.
I'm using ant to run things and thinking that might have an effect I
decided to switch running through the main method. The effect is the
same. No exceptions, and depending on the loop contents different
amounts of the final file being created.
There is definitely something odd going on. I am going to have to strip
this down and get something working, and then built back up from there.
If you have any pointers from the information I provide above I will be
most grateful.
Thanks in advance.
CHEERS> SAM
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: java code in template screwing up ...
Posted by "Geir Magnusson Jr." <ge...@adeptra.com>.
Wow. Wacky. Are you sure that the merge isn't throwing an exception?
Does it matter what you put in the loop?
On Saturday, December 21, 2002, at 03:43 AM, Sam Joseph wrote:
> Hi,
>
> I'm using Velocity 1.2 and I'm having a strange problem from some java
> code in my velocity templates. Apologies for the longish mail, but I
> wanted to try and specify excatly what was happening. Many thanks in
> advance for reading this, and for any help you might be able to
> provide.
>
[SNIP]
--
Geir Magnusson Jr 203-355-2219(w)
Adeptra, Inc. 203-247-1713(m)
geirm@adeptra.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>