Search code examples
struts2radio-buttonjstlstrutsognl

Value of list attribute of radio button from scriplet in Struts 2


I want to read a key and value of list from a loop. Below is the code snippet that I tried but it's not working.

<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>

Solution

  • Try

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

    The variable title is in the page scope, but you don't need a scriptlet to access it.