0

I have below velocity template construct

#if($no_of_entries > 1)          
    <strong>Its True !!</strong>
#else
    <strong>Its False !!</strong>
#end

Even when $no_of_entries is greater than 1 , say 10 , it prints Its False !!

That means $no_of_entries > 1 is not working

Why the $no_of_entries > 1 condition returning false ?

I tried printing the value for $no_of_entries and it prints correct value which is > 1

EDIT :

I also tried using below code

#if( Integer.parseInt($no_of_entries) > 1)    

    <strong>Its True !!</strong>
#else

     <strong>Its False !!</strong>
#end

But it is not working and throwing below exception -

org.apache.velocity.exception.ParseErrorException: Encountered "Integer" at file.vm
Was expecting one of:
    "[" ...
    "{" ...
    "(" ...
    <WHITESPACE> ...
    <STRING_LITERAL> ...
    "true" ...
    "false" ...
    <INTEGER_LITERAL> ...
    <FLOATING_POINT_LITERAL> ...
    <IDENTIFIER> ...
    "{" ...
    <WHITESPACE> ...
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
Atul
  • 1,560
  • 5
  • 30
  • 75

1 Answers1

0

If it's a number it should work, if it's a String, parse it as Integer:

#set($Integer = 0)
#if($Integer.parseInt($no_of_entries) > 1) 

Or if it's a list use size() method

#if($no_of_entries.size() > 1) 
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
  • Yes.I tried same way . It is giving exception : Caused by: org.apache.velocity.exception.ParseErrorException: Encountered "Integer" – Atul Dec 11 '19 at 10:11
  • @Atul see https://stackoverflow.com/questions/2156502/how-to-convert-string-into-integer-in-the-velocity-template/17602578#17602578 – Ori Marko Dec 11 '19 at 10:35