Announcement Announcement Module
No announcement yet.
multiple language droplists, radio button list text entries using resource bundles? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • multiple language droplists, radio button list text entries using resource bundles?


    I'm looking for a way to specify drop down lists and radio button lists with a few static values (not pulled from the database), where the label text for each select option or radiobutton entry is pulled from a resource bundle.

    I found how to use resource bundles when doing a simple form:label.
    <form:label path="firstname"><spring:message code="label.firstname"/></form:label>

    I was hoping something equivalent could be done with the display text for values in <form:select> or <form:radiobuttons> controls.

    Any Spring MVC + Tiles examples or similar view examples on how to accomplish this? Or would I have to create the html tags from scratch, embedding spring:message entries?


  • #2
    Ok, this may not be the simplest way of doing this with Spring, however this is what I came up with:

    (1) Create an Entry class.

    public class Entry<K, V> {

    private final K value;
    public K getValue() {
    return value;

    public V getLabel() {
    return label;

    private final V label;

    public Entry(K k,V v) {
    value = k;
    label = v;

    public String toString() {
    return "(" + value + ", " + label + ")";

    (2) In the controller class populate a List with Entry instances with the Label property set to the resource bundle messages I wanted in the HTML select option values. Add the List to the uiModel for use by Spring to populate the option values when generating the select html

    RequestContext context = new RequestContext(request);

    List<Entry<Boolean, String>> options = new ArrayList<Entry<Boolean,String>>();
    options.add(new Entry<Boolean,String>(false, context.getMessage("label_com_example_option1")));
    options.add(new Entry<Boolean,String>(true, context.getMessage("label_com_example_option2")));

    uiModel.addAttribute("myOptions", options);

    (3) In the view .jspx pass the collection and specify the itemLabel and itemValue properties for the collection class.

    <field:select field="someModelProperty" items="${myOptions}" id="c_com_example_selectLabel" path="myOptions"
    itemValue="value" itemLabel="label"/>