velocity

How to load/access a bean (@Resource) in a custom Velocity tool

I realize this is a slightly funky thing to need to do, but I'm trying to access my Spring messageSource bean from a custom Velocity tool. In most of our codebase, I'm able to just set up a member variable and load it like this: @Resource(name = "messageSource") private AbstractMessageSource _msgSource; However, in this circumstance,...

Atlassian JIRA Plugin Development: How to make variables available to velocity templates

FAIR WARNING: this question is going to be pretty tough to answer unless you have experience with JIRA and have access to their source (enterprise users). Greetings all, I am writing a plugin which extends AbstractIssueSelectAction. I noticed that ${issue.summary}, etc are all available from within my velocity template, however, there...

Useful velocity gadgets

There are lots of interesting JSP tag libraries. I wanted to know what good Velocity gadgets or libraries or resusable components are out there. Please one per answer. ...

Apache Velocity can not Initialize

When i try to initialize velocity engine using VelocityEngine engine = new VelocityEngine(); engine.init(); I encounter the same error when i try Velocity.init(); org.apache.velocity.exception.VelocityException: Failed to initialize an instance of org.apache.velocity.runtime.log.ServletLogChute with the current runtime configura...

BigDecimal evaluated as a string in Velocity, Struts2

I am using struts2 with Velocity 1.5 and Velocity Tools 1.3. In my template I want to do a loop like: #set ($count = ${item.qty}) #foreach($i in [1..$count]) ${item.price} ........... #end ${item.qty} is a BigDecimal but it seems like its passed to Velocity as a String maybe. Since this loop does not work. Replacing to $count...

Apache Velocity Which Variables's are Availible in Template

Is it possible to get a list of variables inside the template and fill them in using the list? I would like my users to create their templates that means i won't know before hand what variables will be available? EDIT: In my template users will decide what gets printed. Such as $users $latest but from my application i won't know wh...

Append # at the beggining of a string generated by a velocity macro

Does anybody know how to get a velocity macro to run when it's prepended by an Octothorpe? I have a velocity macro called #macro(getUniqueID $id) And I want to use it to spit out an id to be used by jQuery.find() which uses CSS selectors which means that the id needs to be prepended by another octothorpe. jquery.find("##getUniqueID...

Is there a way to break from a foreach loop in velocity?

I'm looking for a certain condition by using foreach to iterate through a collection (of permissions). So if I find all that I need and don't need to loop anymore, is there a way to break out of the loop? I am new to velocity and trying to grok this weird language. #foreach ($perm in $space.getPermissions()) #end ...

Configuring velocity within a tomcat web application. (Cookbook wanted)

Hi all, I have recently been introduced to the Velocity project. I have written a template and have run it as a simple Java application. Integration within my existing web project has not been that easy. Can anyone supply a cookbook for integrating Velocity and Tomcat? Thanks all! ...

Velocity - Delete fields when can't be merged

I use velocity to merge a String(template) with field like hi there I'am ${name}, And I'am ${age} old. velocity merged the field ${name} and ${age} with a kind of hashtable: velocityEngine.evaluate(context, writer, "", template); context is the hashtable(or better a VelocityContext type) I want when Velocity can't find the field i...

Velocity sort XML file with dynamic-elements

Let's say I have a XML file wich looks like this: <root> <dynamic-element name='name' type='text' repeatable='true'> <dynamic-element name='prename' type='text' repeatable='false'> </dynamic element> </dynamic-element> </root> In Liferay the XML file will be filled with input. At the and I will have multiple $name-elements. T...

Is there a way to just copy resources when using a Maven archetype (no Velocity)?

We are using a Maven archetype to create an initial setup for projects using our framework, which relies heavily on Freemarker. As a consequence we need to copy a few Freemarker templates when the archetype is used to generate a new project. The problem we ran into is that Maven seems to run Velocity on all of the files listed as resour...

How to proper initialize the nvelocity engine?

As I saw in some examples, and tried to understand throughout the velocity site, there are three ways of initializing the velocityengine: - With the default configurations : .Init() - With the default configurations, plus the properties in a file : .Init(string) - With the default configurations, plus the properties in a collection : .In...

Encoding problems with Apache Velocity include

I have a velocity/html file. I'm trying to include/parse some simple HTML into a page. If I just copy the text directly on the the main file, it works fine: Miranda Kerr hasn’t been a Victoria’s Secret Angel for ... If I create a separate VM file, and include it like so: #parse("topicoftheday/homepagenews.vm") I get bad chara...

Sitemesh + Struts2 + Velocity: Decorators cannot access the context's objects

Hi, I have a struts2 web app using velocity. I am integrating Sitemesh to the project. The decorators are called properly but for some reasons, the objects placed in the context via the toolbox configuration (velocaity related) are not being loaded. Has anyone faced this issue? Thanks a lot ...

Spring MVC: Resolving the view based on User-Agent

Spring Version: 2.5.6 I want to resolve the view to a specific velocity file based on the value of the User-Agent header. My current line of thinking is an implementation similar to the UrlBasedViewResolver such that the user-agent value is Map'd (via context) to a specific directory(value) based on a matching a regular expression(key)...

Apache Velocity: Is there a standard way of verifying the correctness of a template from the command line?

Our website uses the Apache Velocity template language. Our Content Management System already checks any generated XML documents for well-formedness. We've been asked to check documents to catch Velocity syntax errors before pushing the files to the live site. Is there a standard way of verifying the correctness of a Velocity template...

Velocity (VM) template: how to disable for a block of jquery

I have Apache Velocity. I have some jQuery code. I think VM doesn't like when I do things like $img.css("float","left"). How can I completely disable VM parsing within a block of HTML/Javascript ? Thanks ...

How to set up Velocity to find templates in the file system on Windows?

I have a very simple Velocity application that works on Linux and MacOS and fails on Windows. The problem is with the resource locations. I just give it "/" to allow it to recognize file system paths, but on Windows that fails to work for "c:/....." pathnames. I suspect that there is a simpler solution to this, but what? velocityEngine...

Apache Velocity $ vs $!{}

For apache velocity, is there a difference between accessing variables with $ vs. $!{}. If so, what is it? ...