1

I have a list of list of objects and i am putting this nested list inside ModelandView object but I am not able to acccess the list on the JSP page.

<c:forEach items="${product.productCategoryDetails}" var="productCategoryDetails" varStatus="status">
    <tr id="category_row">
        <td><form:label path="productCategoryDetails[${status.index}].category">Category</form:label></td>
        <td>
            <form:select cssStyle="width:134px" path="productCategoryDetails[${status.index}].category.id" cssClass="category">
                <form:options items="${categories}" itemValue="id" itemLabel="name"/>
            </form:select>
        </td>

        <td><form:label path="productCategoryDetails[${status.index}].subcategory">SubCategory</form:label></td>
        <td>
            <form:select cssStyle="width:134px" path="productCategoryDetails[${status.index}].subcategory.id" cssClass="subcategory">
                <form:options items="${subCategories}" itemValue="id" itemLabel="name"/>
            </form:select>
        </td>
    </tr>
</c:forEach>

Code is working perfectly for categories but it is breaking for subcategories.

modelandview.put("subCategories", subCategories); here, subCategories is a list of list of SubCategory objects.

Also, ProductCategoryDetail object has Category and SubCategory fields.

Beau Grantham
  • 3,435
  • 5
  • 33
  • 43
abhijeet
  • 849
  • 2
  • 19
  • 54
  • What's _breaking_? Your rendered HTML has a select with no options? – Beau Grantham May 01 '13 at 14:46
  • yes...for 2nd select...there is no options shown in html.. – abhijeet May 01 '13 at 16:10
  • you can't use a list of lists within form:options trying to access id and name attribute because a list does not have these attributes – marco.eig May 01 '13 at 16:23
  • is there any way out of it...can i use Map ?? – abhijeet May 01 '13 at 16:27
  • @abhijeet see answer in here http://stackoverflow.com/questions/2117557/how-to-iterate-an-arraylist-inside-a-hashmap-using-jstl – apurvc May 02 '13 at 06:23
  • @apurv ... basically i have a set of set of 2 drop downs on a jsp page like following...value list of options of 2nd drop down depends on the value chosen in first dropdown...so here the main problem is that i need to find a key first and then i can find list of options for second drop down but putting key into the map – abhijeet May 02 '13 at 08:57
  • So something like on click of category you want to update subcategories drop down? If yes then probably you are complicating your design. May be fetch a list of Category and a Map of subCategories and use javascript/jquery to update. requirement seems similar to http://stackoverflow.com/questions/16296107/is-it-possible-to-dynamically-reload-a-formselect-with-values-depending-of-the. – apurvc May 02 '13 at 09:27

1 Answers1

0

For subcategory in form:select use code below:

item="{productCategoryDetails.[status.index].subCategories]}"
jnovo
  • 5,659
  • 2
  • 38
  • 56
yogesh
  • 16