lt;s:selectgt; with dynamic list name(lt;s:选择gt;具有动态列表名称)
问题描述
我想遍历包含 <s:select> 列表源名称的字符串列表,但 HTML 输出与预期不符:这是列表的名称是显示,而不是内容.
I want to iterate over a list of strings containing names for <s:select> list source, but the HTML output is not as expected : it's the name of the list that is display, not the content.
我的操作代码:
My Action code:
public class DescriptionTabArchiveAction extends ActionSupport {
private List<String> vegetables = new ArrayList<String>();
private List<String> devices = new ArrayList<String>();
// contain "vegetables" and "devices".
private List<String> selectList = new ArrayList<String>();
@Action("multipleSelect")
public String multipleSelect() {
vegetables.add("tomato");
vegetables.add("potato");
devices.add("mouse");
devices.add("keyboard");
selectList.add("vegetables");
selectList.add("devices");
return SUCCES;
}
// getters and setters
}
JSP:
<s:iterator value="selectList" var="listName">
<s:select list="%{#listName}" />
<!-- I tried with this line too : same behaviour. -->
<%-- <s:select list="#listName" /> --%>
</s:iterator>
我得到了什么(html 输出):
<select name="" id="">
<option value="vegetables">vegetables</option>
</select>
<select name="" id="">
<option value="devices">devices</option>
</select>
我的期望(html 输出):
<select name="" id="">
<option value="tomato">tomato</option>
<option value="potato">potato</option>
</select>
<select name="" id="">
<option value="mouse">mouse</option>
<option value="keyboard">keyboard</option>
</select>
我的问题:
如何动态迭代字符串列表以获得多个具有不同列表源的 <s:select>?
How can I dynamically iterate over a list of string to have multiple <s:select> with different list source?
推荐答案
使用 Map 代替 List
private Map<String, List<String>> selectMap = new HashMap<>();
//getter and setter here
@Action("multipleSelect")
public String multipleSelect() {
vegetables.add("tomato");
vegetables.add("potato");
devices.add("mouse");
devices.add("keyboard");
selectMap.put("vegetables", vegetables);
selectMap.put("devices", devices);
return SUCCESS;
}
修改迭代器以使用地图
<s:iterator value="selectMap">
<s:select list="%{value}" />
...
</s:iterator>
这篇关于<s:选择>具有动态列表名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:<s:选择>具有动态列表名称
- Jersey REST 客户端:发布多部分数据 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
