velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Elton Hughes <ehug...@novaworks.org>
Subject Odd Behavior
Date Wed, 06 Apr 2005 18:30:04 GMT
Hello All,

I am learning Velocity and I am experiencing some odd behavior. I am 
getting output from the template, but just the last line. The template 
has this:

----------
My First Name is $firstName
My Last Name is $lastName
----------

The program is this:

----------
import java.io.StringWriter;
import java.io.Writer;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

public class ContextChaining {

	public static void main(String[] args) throws Exception {
	
		// initialize Velocity
		Velocity.init();
		
		// get the template
		Template template = Velocity.getTemplate("ContextChaining.vm");
		
		// create two contexts for Velocity
		VelocityContext context1 = new VelocityContext();
		VelocityContext context2 = new VelocityContext(context1);
		
		// set the who variable
		context1.put("firstName", "Gandalf");
		context2.put("lastName", "Stormcrow");
		
		// create the output
		Writer writer = new StringWriter();
		template.merge(context2, writer);
		
		// write out
		System.out.println(writer.toString());
		
	} // end of main method
	
} // End of class
----------

Any thoughts?

Elton
=========================================================
  NOVA                        505 W. Olive Ave. Suite 550
  Elton Hughes (IT)			          Sunnyvale CA 94086
  Phone: 408-730-7235                   Fax: 408-730-7643
---------------------------------------------------------


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


Mime
View raw message