Deprecated Garbage Collections – Kenny Lee Chee Wei

A truckload of garbage by Kenny Lee Chee Wei

Javascript support in Spring Velocity Macros

with 4 comments

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>


Written by kennii

July 17, 2007 at 4:35 am

Posted in Spring Framework

4 Responses

Subscribe to comments with RSS.

  1. How does one add the $competitions to the model for rendering in the view?


    October 20, 2007 at 2:13 am

  2. I assume your Controller extends SimpleFormController.

    Add the method below to your Controller.

    protected Map referenceData(HttpServletRequest request){

    Map model = new HashMap();
    Map competitions = new HashMap();
    competitions.add(“1”, “English Premier League”);
    competitions.add(“2”, “Spanish Primera Liga”);
    competitions.add(“3”, “Italian Serie A”);

    model.put(“competitions”, competitions);
    return model;

    Kenny Lee

    October 20, 2007 at 10:35 am

  3. What does “new_match.competition” in the #springFormSingleSelect macro means.
    “new_match” is a command name or what?
    “competition” is an String defined in command class?

    Thanks in Advance.


    November 12, 2007 at 6:48 am

  4. Hi,

    Yep. new_match is the command name.

    “competition” is an object for me. But you can use string also, if all you need is a string.

    For me:

    public class Match{
    private int id;
    private Competiton competition;

    Kenny Lee

    November 13, 2007 at 4:24 am

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: