【问题标题】:Value of list attribute of radio button from scriplet in Struts 2Struts 2中scriplet中单选按钮的列表属性值
【发布时间】:2023-03-26 01:39:01
【问题描述】:

我想从循环中读取list 的键和值。 下面是我尝试过的代码 sn-p 但它不起作用。

<c:forEach items="${mylist}" var="title">
    <c:set var="id" value="${title.key.id}"/>
      <%Integer idInt = (Integer)pageContext.getAttribute("id");
      String idStr = "";
      if(idInt != null && idInt.intValue() > 0){
      idStr = idInt.toString();
      }%>
<s:radio theme="simple" name="selectedOption" list="#{idStr:title.value}"/>
</c:forEach>

【问题讨论】:

  • 为什么是 sriplets?为什么forEach?想做什么?
  • @AleksandrM:我正在尝试从循环中读取列表的键和值。
  • 列表的键?你是说索引吗?
  • @AleksandrM 是索引(listkey)和值
  • 那么title.key.id是什么?

标签: struts2 radio-button jstl struts ognl


【解决方案1】:

试试

<c:forEach items="${mylist}" var="title">
  <s:radio theme="simple" name="selectedOption" list="#{#attr.title.key.id:#attr.title.value}"/>
</c:forEach>

变量title 在页面范围内,但您不需要scriptlet 来访问它。

【讨论】:

    猜你喜欢
    • 2015-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-27
    • 1970-01-01
    相关资源
    最近更新 更多