Announcement Announcement Module
Collapse
No announcement yet.
how to have the dynamic items variable inside form:options forEach loop Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to have the dynamic items variable inside form:options forEach loop

    Any tag library guru can help me on this issue?

    In JSP:

    <c:forEach items="${command.injuries}" var="oneItem" varStatus="status">
    <form:select id="injuries[${status.index}].level1code" cssClass="injClass1"
    path="injuries[${status.index}].level1Code">
    <form:options items="${xyzList_status.index}" itemLabel="description" itemValue="code" />
    </form:select>
    </c:forEach>

    In refrenceData() in java side, I have pre-defined:

    int ind = 0;
    for (injury : Injuries) {
    dataMap.put("xyzList_"+ind, getList4xyz(ind));
    ind++;
    }

    As yout can see, the "items" variable in form:options has to be dynamic and depending on the index value of outer forEach loop and all those "items" values are pre-set in referenceDate() method. However, the "status_index" was not replaced with a numeric value to be used to retrieve the list from dataMap. If I used "xyzList_0" or "xyzList_1", then it works. In another word, the variable for items in form:options has to be hard-coded.

    Any workaround to solve this problem? Your suggest is really appreciated.

  • #2
    Originally posted by gacheng View Post
    Any tag library guru can help me on this issue?

    In JSP:

    <c:forEach items="${command.injuries}" var="oneItem" varStatus="status">
    <form:select id="injuries[${status.index}].level1code" cssClass="injClass1"
    path="injuries[${status.index}].level1Code">
    <form:options items="${xyzList_status.index}" itemLabel="description" itemValue="code" />
    </form:select>
    </c:forEach>

    In refrenceData() in java side, I have pre-defined:

    int ind = 0;
    for (injury : Injuries) {
    dataMap.put("xyzList_"+ind, getList4xyz(ind));
    ind++;
    }

    As yout can see, the "items" variable in form:options has to be dynamic and depending on the index value of outer forEach loop and all those "items" values are pre-set in referenceDate() method. However, the "status_index" was not replaced with a numeric value to be used to retrieve the list from dataMap. If I used "xyzList_0" or "xyzList_1", then it works. In another word, the variable for items in form:options has to be hard-coded.

    Any workaround to solve this problem? Your suggest is really appreciated.
    Since the list is depending on one particular item inside the loop, create a class variable with getter and setter to hold the xyzList and then pre-set it in the formingBackObject() method. In the jsp, access it as this:

    <c:forEach items="${command.injuries}" var="oneItem" varStatus="status">
    <form:select id="injuries[${status.index}].level1code" cssClass="injClass1"
    path="injuries[${status.index}].level1Code">
    <form:options items="${oneItem.xyzList}" itemLabel="description" itemValue="code" />
    </form:select>
    </c:forEach>

    Comment

    Working...
    X