velocity

Velocity string function

末鹿安然 提交于 2019-11-29 16:02:36
问题 I just start using Java Velocity. Now I want to create a java class template. package $app.package_namespace public class ${app.name}Station { #foreach($s_attribute in $app.station) $s_attribute.type $s_attribute.name, #end public $app.name Station(#foreach($s_attribute in $app.station) $s_attribute.type $s_attribute.name; #end) { #foreach($s_attribute in $app.station) $s_attribute.name=$s_attribute.name; #end } #foreach($s_attribute in $app.station) public ${s_attribute.type} get${s

How to access elements of array after using string.split in Velocity?

霸气de小男生 提交于 2019-11-29 14:03:21
I am using Velocity Templating Language and currently have: #set ( $stringList = $string.split(",") ) which works fine and splits the string up using a ',' as a delimiter as expected. My question is how do i now access each of the elements in the $stringList? I have tried: $stringList.get(0) $stringList[0] $stringList.[0] ${stringList}.get(0) I am using Velocity in JIRA and JIRA happens to use Velocity version 1.4 which apparently doesn't have support for accessing arrays as tried above. Any help is much appreciated. It works when I convert the array to a List using Arrays.asList() and then

How to access an object's public fields from a Velocity template

橙三吉。 提交于 2019-11-29 13:25:43
Here is my object class: public class Address { public final String line1; public final String town; public final String postcode; public Address(final String line1, final String town, final String postcode) { this.line1 = line1; this.town = town; this.postcode = postcode; } } I add it to the velocity context like this: Address theAddress = new Address("123 Fake St", "Springfield", "SP123"); context.put("TheAddress", theAddress); However, when writing the template, the following will not render the address fields (however, it works fine when I add getters to the Address class) <Address> <Line1

getClass().getClassLoader().getResourceAsStream() is caching the resource

末鹿安然 提交于 2019-11-29 09:25:35
I have a resource (velocity template) which I'd like to be able to swap during development. However, getClass().getClassLoader().getResourceAsStream() seems to cache the template. Is there a way to disable this besides using a file loader instead of the class loader? To avoid caching you can use: getClass().getClassLoader().getResource().openStream() It would be equal to using URLResourceLoader for Velocity instead of ClasspathResourceLoader I suppose. I would just go with a file loader. See if something like this helps (exception handling omitted): URL res = getClass().getClassLoader()

Escaping quotes in velocity template

妖精的绣舞 提交于 2019-11-29 09:09:30
I have a java method, that takes a few strings. This method needs to be called from a Velocity Template. However, the strings are too complex, with lots of single quotes, double quotes and commas as well. As a result merge is failing. Is there a way to escape quotes in Velocity? It depends on which version of Velocity you're using. Velocity 1.7 has clear rules for escaping quotes: just double the same type of quotes used to wrap the string: $object.callMethod('Let''s have fun with "quotes"', "Let's have fun with ""quotes""") Prior to that, there were some fuzzy rules with backslash escapes

Calling class methods (static) from inside a velocity view page

有些话、适合烂在心里 提交于 2019-11-29 05:38:20
Can you call class methods from inside a view page? Specifically ones that are not passed into the view? In asp.net MVC I can do this: <%= SomeClass.FixDateFormat(ViewData.Model.SomeClass.DateCreated) %> Since this came up in the top of my google search on this topic it seems like folks might like to see an updated answer when they get this on the top of their search... (found this here: http://velocity.10973.n7.nabble.com/Use-of-static-functions-td15126.html ) in Velocity 1.5 or earlier, you can just use: #set( $String = '' ) #set( $foo = $String.format('%.1f', $dataFedIn) ) because you can

VelocityEngineUtils has been removed in Spring 3.2 so what else to use?

风流意气都作罢 提交于 2019-11-29 03:54:17
Today I have upgraded my entire Spring web application from using Spring 3.1.1 to Spring 3.2 . Most part of my existing app does not break except that in Spring 3.2 , the org.springframework.ui.velocity.VelocityEngineUtils class seems to be removed completely from the spring-context-3.2.0.RELEASE.jar . I found the migration guide as in this url. It stated that org.springframework.ui.velocity.VelocityEngineUtils class has just been deprecated, but in fact it has been removed completely. Maybe I'm just mistaken, I would like to know if the VelocityEngineUtils class still exist in somewhere or if

Velocity, what's the most efficient way to check if a string is empty and not null

房东的猫 提交于 2019-11-29 02:54:50
I often have cases when a string value is absent and/or empty. Is this the best way to test this condition? #if( $incentive.disclaimer && $!incentive.disclaimer != '' ) $incentive.disclaimer #end If you just want Velocity to display the value if there, or display nothing if absent, a quiet reference by itself will do the trick: $!incentive.disclaimer If you're wanting to explicitly test for empty, StringUtils from Apache Commons Lang can help. First add it to your Context (reference here ): context.put("StringUtils", StringUtils.class); Though if you're on an older version of Velocity, it may

$null check in velocity

[亡魂溺海] 提交于 2019-11-29 02:48:46
I came to know about null check using $null in velocity 1.6 through a resource updated by you. Resource: Reading model objects mapped in Velocity Templates But I am facing so many challenges that there is no $null for null check in velocity as there is no documentation provided about this. Please provide me with documentation stating $null as valid for null check in velocity. Thanks in Advance lucky To check if a variable is not null simply use #if ($variable) #if ($variable) ... do stuff here if the variable is not null #end If you need to do stuff if the variable is null simply negate the

Spring Boot开发之流水无情(二)

扶醉桌前 提交于 2019-11-29 00:18:52
上篇 散仙写了一个很简单的入门级的Spring Boot的例子,没啥技术含量,不过,其实学任何东西只要找到第一个突破口,接下来的事情就好办了,人最怕什么? 我想莫过于干一件事情,没有下手的地方了,而当你一旦找到了这感觉,就可以很喜悦的顺藤摸瓜般的探索你强烈想探索求知的某种事物了,这种冥冥之中玄而又玄的感觉是什么?回想一下: (1) 当你把第一个某种编程语言的Hello World的例子,成功的运行在一个IDE中 (2) 当你第一次从老家出发到达了某个你从未涉足过的地方 (3) 当你成功的完成了第一次网购 一切的不相关的事物之间的,其实都有类似的学习历程,正是所谓的触类旁通,万法归宗! 关于Spring Boot这块,其实里面涉及的内容非常多也非常灵活,散仙的项目中用到的模块也只是冰山一角,不可能完全覆盖所有有关的模块,完全是为了项目而用技术,不是为了技术而诞生了这个项目,所以这次记录的心得,完全是项目有关的,而不是Spring Boot一个学习教程,这一点,希望各位看官明白,如果想专攻学习Spring Boot,推荐点击官网更详细的 教程 一个项目是由多种不同层面的技术组成的,所以散仙不会只写有关Spring Boot方面的,虽然Spring Boot是主线。大多数情况下,都会集成多种不同的技术,只有各自发挥自己擅长的优势,才能组合出最优的架构。 好了,多说了点废话