How to choose a value of a HashMap in select Struts2?

回眸只為那壹抹淺笑 提交于 2021-02-19 03:54:26

问题


I ran into a problem with Struts2. I have a HashMap<String, Integer> that I use in a form with a select to choose name and corresponding id to that name.

HashMap iterates and populates my <select>list with names. I only need an id to pick. How do I pick an id/value instead of a name/key?

companyMap is a HashMap, where <String, Integer> or key, value.

companyName is a String.

<s:select label="Pick the company name" 
    headerKey="-1" headerValue="Select Company name"
    list="companyMap.keys" 
    name = "companyName"
/>

回答1:


If the list is a Map (key, value), the Map key will become the option 'value' parameter and the Map value will become the option body.

But you need to change this rule

<s:select label="Pick the company name" 
    headerKey="-1" headerValue="Select Company name"
    list="%{companyMap.entrySet()}" 
    name = "companyId"
    listKey="value"
    listValue="key"
/>


来源:https://stackoverflow.com/questions/39666093/how-to-choose-a-value-of-a-hashmap-in-select-struts2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!