Archive for July 2007
Javascript support in Spring Velocity Macros
I’m using Velocity templates as the “view” for a new Spring MVC project.
Velocity Spring macros are available which can be used to bind object attributes to the html form elements.
While reading Chapter 14 from Spring MVC documentation, i noticed the VTL definition for a html select element looks like #springFormSingleSelect( $path $options $attributes).
We can pass javascript behaviour into the $attribute parameter like,
#springFormSingleSelect( "new_match.competition" $competitions "onchange=updateTeams()")
which produces,
<select id="competition" name="competition" onchange=updateTeams()> <option value="1">English Premier League</option> <option value="2">Spanish Primera Liga</option> <option value="3">Italian Serie A</option> </select>