简体   繁体   中英

how to display value to the select tag in struts2

How to display value to the select tag in struts2, I am using list of values as Map

My code

first type:

action class,

private Map<Integer, String> mapForSelect;

    mapForSelect.put(1, "map 1");
    mapForSelect.put(2, "map 2");
    mapForSelect.put(3, "map 3");
    mapForSelect.put(4, "map 4");
    mapForSelect.put(5, "map 5");
    mapForSelect.put(6, "map 6");
      ..........
         .........

settres and getters for "mapForSelect"

jsp page,

<s:select label="Map Demo" list="mapForSelect" value= "3" />

It will show select default value as "map 3"

second type:

private Map<String, String> mapForSelect;

    mapForSelect.put("one", "map 1");
    mapForSelect.put("second", "map 2");
    mapForSelect.put("three", "map 3");
    mapForSelect.put("four", "map 4");
    mapForSelect.put("five", "map 5");
    mapForSelect.put("six", "map 6");
      ..........
         .........

settres and getters for "mapForSelect"

jsp page,

<s:select label="Map Demo" list="mapForSelect" value= "three" />

This time that select doesn't show any default value, I want to this way to show default value.

please give solution for this.

Thanks in advance.

使用value="'three'"代替,因此该值将是一个字符串。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM