Questions tagged [velocity]

Apache Velocity is a Java-based template engine. It can be used to dynamically generate web pages, email messages, source code, or any other text file.

Apache Velocity is a Java-based template engine. It can be used to dynamically generate web pages, email messages, source code, or any other text file.

Apache Velocity is a project of the Apache Software Foundations (ASF).

More information is available at the project home page: http://velocity.apache.org.

From the developer perspective, the fundamental pattern for rendering a text file is:

  • Create and initialize a VelocityEngine.
  • Add your data objects to a Context (essentially, a map of objects available for use in the template)
  • Choose a template
  • Merge the template with the context.

This can be done in a few lines of Java code, or you can use one of several frameworks to integrate this with your application.

One of the most popular web application frameworks which integrates Velocity is the Spring Framework. For simple servlet based applications, most developers use one of the Velocity Tools servlets (also available from the Apache Velocity project).

Useful Online Resources

  1. Velocity User Guide
  2. Velocity Developer Guide
2370 questions
0
votes
1 answer

Why isn't Velocity displaying

I have problem with Apache Velocity engine. I have a piece of html in my template:

${contextString}: ${context.contextTitle}

${published}
hc0re
  • 1,806
  • 2
  • 26
  • 61
0
votes
2 answers

2 variable foreach loop in Velocity Template Language

Is there any way to use 2 variables in foreach loop ? #foreach( $name in $names && $method in $methods ) $name : $method #end Because I want to print the result side by side
0
votes
1 answer

Solr Velocity displays Error 400 on filter queries

While using Velocity Solr I encounered an Error 400. It only occurs when I have three or more filter querys. I noticed that the query passed in the url…
0
votes
2 answers

For loop in velocity template

I would like to use the for loop in velocity template like below - for(int i = 0; i < 10; i++){} Any idea how to define in vm? Thanks in advance
Balaji
  • 859
  • 1
  • 16
  • 27
0
votes
1 answer

Is There A Library That Converts Any String Into A Valid Class Name That Is Compliant To Code Conventions

For some code generation I look for a library that can convert any String to a java code convention compliant class name. E.g. 2some_File_name should be converted to SomeFileName I want to use the converted String in a template engine to generate…
Marcus Held
  • 635
  • 4
  • 15
0
votes
2 answers

Why is my Velocity Template Language conditional not working?

I'm building a response template for an AWS API Gateway endpoint to handle errors. The incoming JSON error message looks like one of the following: { "__type": "UserNotFoundException", "message": "User does not exist." } { "__type":…
dusk
  • 1,243
  • 1
  • 9
  • 10
0
votes
1 answer

Getting the absolute context path of a webapp inside a Velocity template

I have a fairly simple (I hope :P) question. I know that in good old Java servlet code, I can derive the full request path of a request that comes into the web server like this: String requestBaseUrl = String.format("%s://%s:%s%s",…
Jesús Zazueta
  • 1,160
  • 1
  • 17
  • 32
0
votes
0 answers

I need to get the value of the Marketo custom object

I have developed a batch that retrieves our site's DB data and import into Marketo custom object with API. I tying to display this custom object’s value in the email body, but it is failing. Script editor shows the custom object name but My token…
mazaka
  • 5
  • 4
0
votes
1 answer

Configuration error with SimpleLogger (SLF4j) in Velocity

I am having some difficulty configuring some loggers for velocity in Spring. I am using Velocity 2.1, Spring 5.2.2 and SLF4J 2.0.0 org.slf4j.simple.SimpleLogger object set as runtime.log.instance is not a valid org.slf4j.Logger implementation. I am…
hell_storm2004
  • 1,401
  • 2
  • 33
  • 66
0
votes
0 answers

Replace XML value in Velocity

I will preface the below with stating i am new to Java in general: I have the need to insert the a value into an already existing XML in the below case for the attribute "directory".
0
votes
1 answer

How to assign the result of `#evaluate` to a variable?

Context: Inside a XWiki site, I heavily use velocity templates to have specific representation of objects. In a particular template, I need to be able to have one indirection level to allow special processing for some fields. I managed to put the…
Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252
0
votes
1 answer

Is it possible to define several velocity macroses?

Is it possible to define several velocity macroses? Like this: #macro (cap $strIn) $strIn.valueOf($strIn.charAt(0)).toUpperCase()$strIn.substring(1) #end ## #marco (lowFirst $strIn) …
Vladimir
  • 12,753
  • 19
  • 62
  • 77
0
votes
1 answer

Velocity Template Language: How to import EscapeTool

I am trying to use unurl for my mapping template. $url -> hello here & there $esc.url($url) -> hello+here+%26+there $esc.unurl($esc.url($url)) -> hello here & there I wrote the following mapping…
Joey Coder
  • 3,199
  • 8
  • 28
  • 60
0
votes
2 answers

velocity Implementing nested variable resolution

I want to generate controller layer code through velocity. I generate a mapping method: @ResponseBody @PostMapping(value = "\\${peacetrue.${moduleName}.urls.add}") public ${ModuleName}VO add(${ModuleName}Add params) { logger.info("add…
peacetrue
  • 186
  • 1
  • 15
0
votes
1 answer

If Else Construct with Comparison not Working In Velocity Template

I have below velocity template construct #if($no_of_entries > 1) Its True !! #else Its False !! #end Even when $no_of_entries is greater than 1 , say 10 , it prints Its False !! That means…
Atul
  • 1,560
  • 5
  • 30
  • 75
1 2 3
99
100