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!!

19 comments:

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. Hi buddies, it is great written piece entirely defined, continue the good work constantly. SIBO

    ReplyDelete
  8. 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
  9. 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
  10. 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
  11. They maintain constant communication, responding quickly to any questions or concerns.interaction design firms project management is phenomenal, and they proactively ensure goals are met.

    ReplyDelete
  12. 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. Dogecoin free

    ReplyDelete
  13. It doesn't get any better than that! I’ve had other web hosting carriers, but this business enterprise keeps outperforming them all. Thanks…..
    top web design firms

    ReplyDelete
  14. They were always on time, and their project management is perfect
    brand services SF

    ReplyDelete
  15. Remarkable blog! I have no words to praise, it has really allured me.
    Bay Area web design companies

    ReplyDelete
  16. Just saying thanks wouldn’t just be enough, for the fantastic fluency in your writing.
    best UX agency

    ReplyDelete
  17. Each time I used to always check blog posts within the first hours in the break of day, because I like to get information increasingly more.
    best UX design agencies

    ReplyDelete

LinkWithin

Related Posts Plugin for WordPress, Blogger...