Results 1 to 2 of 2

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

  1. #1
    Join Date
    Dec 2004
    Posts
    4

    Default 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. #2
    Join Date
    Dec 2004
    Posts
    4

    Default

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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •