Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Struts velocity template

Have Programming Question? Ask it here!
 
 
 


ash
velocity template
1 Answer(s)      5 years and 7 months ago
Posted in : Struts



Advertisement
View Answers

January 6, 2009 at 4:07 AM


Hi friend,

Velocity is an open source templating tool developed by an international volunteer community and hosted by the Apache Software Foundation's Jakarta Project.


Here is simple code:


import java.io.*;
import java.io.StringWriter;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;

public class HelloWorld {
public static void main( String[] args ) throws Exception {
VelocityEngine vengine = new VelocityEngine();
vengine.init();
// next, get the Template
Template temp = vengine.getTemplate("helloworld.vm");
//create a context and add data
VelocityContext context = new VelocityContext();
context.put("name", "World");
// now render the template into a StringWriter
StringWriter writer = new StringWriter();
temp.merge(context, writer);
System.out.println(writer.toString() );
}
}

-------------------------------------

Thanks.

Amardeep



Related Tutorials/Questions & Answers:
velocity template - Struts
velocity template  what is velocity template and how does it work? whats the flow of execution of velocity template? i want an example using velocity template?  Hi friend, Velocity is an open source templating tool
XML handling in a template using Velocity
XML handling in a template using Velocity   ... in a velocity template and also shows that use of  macro to wrap HTML tag in velocity  template. The method used in this example 
Advertisements
how to render my htmlstring from java class in velocity template?
how to render my htmlstring from java class in velocity template?  Hi, I have a java class generates html string dynamically based on the logic. I'm...! Ref: I read your article "Use Velocity to generate HTML document". -Chintu
Velocity
; Apache Velocity is template engine developed by apache foundation... applications. In this tutorial you will learn Velocity template with the help... you how to call class method in velocity template.   
Define and use Macro in Velocity
Define and use Macro in Velocity   ... in velocity  template and also shows how to use Iterator in velocity  template...:- Initialize velocity run time engine through method  init(). 2:- Create object
Velocity Macro with Parameters
Velocity Macro with Parameters   ... with parameters in velocity  template. Example given below show you, how to display date and time velocity. The method used in this example 
Velocity Iterator Tool Example
Velocity Iterator Tool Example     ...; template. The method used in this example are described below:-  1:- Initialize velocity run time engine through method  init(). 2:- Create object
How to use foreach loop in velocity
How to use foreach loop in velocity   ... in velocity  template. The method used in this example are described below:-  1:- Initialize velocity run time engine through method  init(). 2:- Create
XML and Velocity
XML and Velocity  How to create xml file using velocity template engine
What is Velocity?
What is Velocity?       Velocity is a Java-based template engine. It permits... Velocity Template Language (VTL): The Velocity
Show content of .vm file as output using Velocity
Show content of .vm file as output using Velocity  ... content of .vm file using velocity and also shows how to use Iterator in velocity  template. The method used in this example are described below:- 
Use macro to wrap HTML tags in velocity
Use macro to wrap HTML tags in velocity   ... in velocity  template. The method used in this example are described below:-  1:- Initialize velocity run time engine through method  init
Hibernate Template
Hibernate Template  Define Hibernate Template
XML template
XML template  Hi..... please tell me about What is XML template? Thanks
Use if in velocity
Use if in velocity       This example shows you how to use if statement in velocity. Description of methods used in the example given below.... 1:- Initialize velocity run time
Velocity with External Properties
for controlling template methods and properties. "runtime.log = velocity_example.log... Velocity with External Properties       This Example shows you how to use Velocity
The benefits of Hibernate Template.
The benefits of Hibernate Template.  What are the benefits of Hibernate Template
Use if and elseif statements in velocity
Use if and elseif statements in velocity   ... in velocity. The method used in this example are described below:-  1:- Initialize velocity run time engine through method  init(). 2
How to define variable in Velocity
How to define variable in Velocity   ... in velocity. Methods used in this example are described below:- 1:- Initialize velocity run time engine through method  init(). 2:- Create object
How to use List in velocity
How to use List in velocity       This Example shows you how to use List in velocity. ... velocity run time engine through method  init(). 2:- Create object
How to use Map in velocity
How to use Map in velocity       This Example shows you how to use map in velocity. The method... velocity run time engine through method  init(). 2:- Create object
Use if else and end statements in velocity
Use if else and end statements in velocity  ... if in velocity. The method used in this example are described below:- 1:- Initialize velocity run time engine through method  init(). 2:- Create object
Include template file in another template file
Include template file in another template file  ... template file. The method used in this example are described below:-  1:- Initialize velocity run time engine through method  init(). 2
Html Template - JSP-Servlet
Html Template   I use a template to design my website,but some problems arised using template.I pass flag update and insert as a hidden field on to the servlet,the response of the servlet is a jsp page.on this page template
How to use dollar sign in velocity
How to use dollar sign in velocity   ... in velocity. The method used in this example are described below:- 1:- Initialize velocity run time engine through method  init(). 2:- Create object
Template - Java Beginners
Template  Develop a template for linked-list class along with its methods in Java
Velocity Web Edit
Velocity Web Edit       Velocity Web Edit is a Velocity and HTML aware editor... Assist  Velocity Variables Names  Velocity Variable Methods
Integration of velocity with struts 2.0 - Struts
Integration of velocity with struts 2.0  Hi , I am going to implement Struts 2 with Velocity. Is there any plugin available? I am totally new to velocity. Please tell the steps to integrate Struts 2 and velocity
Replacing a template with actual values
Replacing a template with actual values  I have a template Hello $$personename$$, You are eligible for this $$planname$$ from today onwards. CONDITIONAL_TEXT_1 Regards,$$managerName$$ I wanna repalce this place
Foreach loop with negative index in velocity
Foreach loop with negative index in velocity  ... with negative index in velocity. The method used in this example are described below:- 1:- Initialize velocity run time engine through method 
Call class methods
; This Example shows you how to call class method in velocity template.  Steps used in the code given below : 1: Initialize velocity... this (Date) object in velocity template.   CallClassMethods.java
How to set a variable value using velocity
How to set a variable value using velocity  ... using velocity. The method used in this example are described below:- 1:- Initialize velocity run time engine through method  init(). 2:- Create
Smarty Templates PHP, Smarty Template Tutorials
Learn Smarty Templates Engine for PHP Smarty is template engine for PHP, it enables the php programmers to develop web applications using the smarty templates. Learn how to create Smarty Template now.    
Use Velocity to generate HTML document
Use Velocity to generate HTML document   ... document using velocity. The method used in this example are described below:-  1:- Initialize velocity run time engine through method  init(). 2
Reference Class Properties
in your velocity template.  Steps used in the code given below : 1: Initialize velocity run time engine through method  init(). 2: Create object...; Velocity.getTemplate("./src/velocity/ClassReference/ClassProperties.vm");  
POI Word document (Letter Template)
POI Word document (Letter Template)  Dear Team, i need code for generating word document(letter format). i am unable to get the code for formats, font settings, letter type settings. please help me for the same. Thanks
Simteec
. It it based upon the velocity template engine. Code is generated by specifying a template- and a properties-file, which is needed to define the variables for the template. Contact here for more detail: http://simteec.sourceforge.net
Show output as a xml file using Velocity
Show output as a xml file using Velocity   ... in velocity. The method used in this example are described below:-   1:- Initialize velocity run time engine through method  init(). 2
How to find the exact PHP template I need?
How to find the exact PHP template I need?  Hi! I'm a PHP Pro?I think I am one?, but this is the first time for me to try a PHP template, so I have... the/a right PHP template? Needs for a PHP Template: - it is efficient since the PHP
Create project from Maven Template
In this section, you will learn to create a simple Java web application project from Maven Template
How to create Velocity Engine .vm file for Andorid Appication
How to create Velocity Engine .vm file for Andorid Appication  Hi, I want to create a .vm file of Velocity File for Android Application.please help me to do
how to use Excel Template to write excel file using java
how to use Excel Template to write excel file using java  How to use Excel template to write data in that file using java
how to expose blob in restful web service client java rest template
how to expose blob in restful web service client java rest template  how to expose blob in restful web service client java rest template
useitgenerator
useitgenerator       UseitGenerator is a lightweight generator for eclipse uml2 models. It is base on the velocity template engine. It has a simple generation process. You
Data Type: number
; This Example shows you how to use number data type in velocity. Methods used in this example are described below:-  1:- Initialize velocity run... of VelocityContext Class. 3:- Create Template class object, Template  class object is used
How to pass java.util.Properties in properties
java.util.Properties to in velocity. The methods used in this example are described below:-  1:- Initialize velocity run time engine through method  init(). 2:- Create object of VelocityContext Class. 3:- Create Template
Data Type: bool
; This Example shows you how to use bool datatype in velocity. Methods used in this example are described below:- 1:- Initialize velocity run time...;Class. 3:- Create Template class object, Template class object is used
Date Tool Example
; This Example shows you how to display date and time velocity. ... velocity run time engine through method  init(). 2:- Create object of VelocityContext Class. 3:- Create Template class object, Template  
Struts Theme And Template
Struts Theme And Template Example To make a theme based application in struts in need to add the following mapping in struts.xml file <constant name="struts.ui.theme" value="themeDirectory" /> <constant
 

 

 

DMCA.com