Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Some tutorials on the internet recommend setting a variable $Integer to the constant of 0 and then calling parseInt method on it like this:

Code Block
themeDJango
languagehtml/xml
#set ($Integer = 0)
#if ($parameters.get("ItemsPerPage"))
  #set ($ItemsPerPage = $Integer.parseInt($parameters.get("ItemsPerPage")))
#else
  #set ($ItemsPerPage = 6)
#end

The problem is that $Integer.parseInt won't handle bad input gracefully.  Instead the proper way to code this type of logic is:

Code Block
themeDJango
languagehtml/xml
#set ($ItemsPerPage = 6)
#if ($formatHelper.parseInteger($parameters.get("ItemsPerPage")))
  #set ($ItemsPerPage = $formatHelper.parseInteger($parameters.get("ItemsPerPage")))
  #if ($ItemPerPage < 1 || $ItemPerPage > 50)
    #set ($ItemsPerPage = 6)
  #end
#end

...