0

I have a LinkedHashMap as shown below -

LinkedHashMap<String, ArrayList<MSCategoryDetailsBO>> categoryMap =
                new LinkedHashMap<String, ArrayList<MSCategoryDetailsBO>>();

MSCategoryDetailsBO has poperty like categoryIsSelected, categoryName..

when I am trying to iterate this map on JSP using JSTL as shown below -

<c:forEach items="${CategoryMap}" var="item1" varStatus="status">
    <c:set var="categoryList" value="${item1.value}" />
    <c:forEach items="${categoryList}" var="item2" varStatus="status"
                            begin="0" end="9">
        <c:if test="${(item2.categoryIsSelected eq false) || 
                                             (empty item2.categoryIsSelected)}">
            ${item2.categoryName}
        </c:if>
    </c:forEach>
</c:forEach>

but i am getting

E /MSGenericJSPPageError.jsp - Property 'categoryIsSelected' not found on type java.util.LinkedHashMap$LinkedHashMapEntry javax.el.PropertyNotFoundException: Property 'categoryIsSelected' not found on type java.util.LinkedHashMap$LinkedHashMapEntry at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:200) at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:177)

Braj
  • 46,415
  • 5
  • 60
  • 76
Vivek
  • 10,978
  • 14
  • 48
  • 66

3 Answers3

0

When you iterate over a Map, you're getting Map.Entry objects (you can see that in your stack trace that it is looking for your property on a java.util.LinkedHashMap$LinkedHashMapEntry object). You can access the key with 'type' and the value with 'value'.

So, for your code, maybe try item2.value.categoryIsSelected.

Also see this question.

Community
  • 1
  • 1
Mike D
  • 64
  • 7
0

Make sure MSCategoryDetailsBO is public class and contains valid getter/setter for all the properties/members that is needed in JSP.

JSTL uses reflection so that you can access the properties of an object via dot notation, if they follow the JavaBean naming-convention.


Its clear from the Exception itself that the property that you are trying to access are not have a matching getter method.

PropertyNotFoundException: Property 'categoryIsSelected' not found on type

Class MSCategoryDetailsBO should look like:

public class MSCategoryDetailsBO {
    private boolean categoryIsSelected;
    private String categoryName;

    public void setCategoryIsSelected(boolean categoryIsSelected) {
        this.categoryIsSelected = categoryIsSelected;
    }

    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }

    public boolean getCategoryIsSelected() {
        return this.categoryIsSelected;
    }

    public String getCategoryName() {
        return this.categoryName;
    }
}

Please validate below condition again that means you want to show the categoryName if categoryIsSelected is false or empty.

<c:if test="${(item2.categoryIsSelected eq false) || (empty item2.categoryIsSelected)}">
      ${item2.categoryName}
</c:if>
Community
  • 1
  • 1
Braj
  • 46,415
  • 5
  • 60
  • 76
0

Make sure MSCategoryDetailsBO class has setters and getters for fields: categoryIsSelected, categoryName. Why do you want to put begin and end in the second forEach loop, are you sure your list size is 10 before hand? You can get item number using varStatus fields: index (starting from zero ) and count (starting from 1). Also you don't have to set the arrayList to separate variable.

    <c:forEach items="${CategoryMap}" var="item1" varStatus="status1">
        <c:forEach items="${item1.value}" var="item2" varStatus="status2">
            <c:if test="${(item2.categoryIsSelected eq false) || (empty item2.categoryIsSelected)}">
                ${item2.categoryName}
            </c:if>
        </c:forEach>
    </c:forEach>
Prasad
  • 3,785
  • 2
  • 14
  • 23