FreeMarker put commas in my integer

FreeMarker formatted an integer with a comma when I didn’t expect it. This caused my form post to fail. I was using the template language FreeMarker to generate HTML pages. The application included several simple web forms for editing objects in the database. The forms included a hidden field for the database id of the object being modified.

<input type="hidden" name="id" value="${id}">

The database id was an integer. The application worked fine until the database id reached 1000. Then FreeMarker formatted the integer as 1,000, which my backend server considered an invalid integer because of the comma.

To fix this, I used the “computer language” builtin ?c to force FreeMarker to format the value without a comma.

The corrected line is

<input type="hidden" name="id" value="${id?c}">

To avoid this problem in your application, you might consider starting all database ids at 1000 so this problem is found immediately.

Be careful out there.