Saturday, February 22, 2014

Velocity without template(.vm) file

Velocity can be used without a .vm file.
The original template string could be stored in other places, eg. database, or coded in java class.

But there are slightly different to merge the template string with the passed in parameters.

Below is the sample code.
// template string coded in java class or retrieve from database
String templateString = "Using $project $name without vm file.";

// initialize Velocity
VelocityContext context = new VelocityContext();
context.put("name", "Velocity");
context.put("project", "Jakarta");

String output = new StringWriter();

// evaluate the template string and merge them together
Velocity.evaluate(context, output, "log or null", templateString);
System.out.println("output: " + output);

***to use Velocity with .vm file, we use template.merge( context, output )
***to use Velocity without .vm file, we use Velocity.evaluate( context, output, logTag, templateString )


Done!!

11 comments:

  1. frases Hi, great to see your website. I like the content and the research done behind every aspect of your blog. It looks great and very knowledgeable. Keep it up the good work.

    ReplyDelete
  2. They're produced by the very best degree developers who will be distinguished for your polo dress creating. You'll find polo Ron Lauren inside exclusive array which include particular classes for men, women. hyip template

    ReplyDelete
  3. Just pure brilliance from you here. I have never expected something less than this from you and you have not disappointed me at all. I suppose you will keep the quality work going on. hyip template

    ReplyDelete
  4. I finally found great post here.I will get back here. I just added your blog to my bookmark sites. thanks.Quality posts is the crucial to invite the visitors to visit the web page, that's what this web page is providing. website builder cost

    ReplyDelete
  5. I was taking a gander at some of your posts on this site and I consider this site is truly informational! Keep setting up.. uvc light

    ReplyDelete
  6. All the contents you mentioned in post is too good and can be very useful. I will keep it in mind, thanks for sharing the information keep updating, looking forward for more posts.Thanks best digital marketing course

    ReplyDelete
  7. I have bookmarked your website because this site contains valuable information in it. I am really happy with articles quality and presentation. Thanks a lot for keeping great stuff. I am very much thankful for this site. Cabin in Missouri

    ReplyDelete
  8. Hi buddies, it is great written piece entirely defined, continue the good work constantly. SIBO

    ReplyDelete
  9. Very informative post ! There is a lot of information here that can help any business get started with a successful social networking campaign ! Vanity mirror

    ReplyDelete
  10. Very useful post. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. Really its great article. Keep it up. trump hat

    ReplyDelete
  11. This is a great post. I like this topic.This site has lots of advantage.I found many interesting things from this site. It helps me in many ways.Thanks for posting this again buy hyip

    ReplyDelete

LinkWithin

Related Posts Plugin for WordPress, Blogger...