Reputation: 3631
I have a Maven archtype that use a requiredProperty
that contains a number, but the velocity variable are string. So, in my template I can't test if this property is greater than a number:
#if( $myVar gt 5 )
I have tested the following solution without success.
I've also tried this:
#set( $intVar = Integer.parseInt($myVar) )
That's also fail at the archetype generation.
Any advice?
Upvotes: 2
Views: 1086
Reputation: 346
I have implemented user input validation based on a regular expression provided in the archetype descriptor :
https://issues.apache.org/jira/browse/ARCHETYPE-487
hopefully it will solve this issue for future versions of the maven archetype plugin.
Upvotes: 0
Reputation: 11601
You can't reference classes from Velociy, so Integer.parseInt
won't work. However, since in Java any static method can be called as an instance method, and Velocity is just Java in disguise, you can call parseInt
on any integer. So you can try this trick:
#if ($myVar.length().parseInt($myVar) gt 5)
You're getting hold of an integer starting from the one variable that you're assuming you have, $myVar
.
Upvotes: 1