1

On my doGet of the page I setup some default attributes.

    private static final CategoryFactory cf = CategoryFactory.getInstance();

public static void setupHeader(HttpServletRequest req) {
    ArrayList<String> catagories = cf.getPrimaryCategories();
    Map<String, ArrayList<String>> categoryMap = cf.getCategoryMap();
    User user = UserUtils.getUserSession(req);

    req.setAttribute("catagories", catagories);
    req.setAttribute("categoryMap", categoryMap);
    req.setAttribute("isAdmin", UserUtils.isAdmin(user));
    if (user != null) {
        req.setAttribute("orderCount", user.getOrderCount(false));
        req.setAttribute("unreadMessageCount", user.getUnreadMessageCount());
        req.setAttribute("cartTotal", user.getShoppingCart().getTotal());
    }
}

Then on my JSP page I'm trying to work with the categoryMap based on the catagories which are the keys from Map.

<c:forEach var="cata" items="${catagories}">
<li class="dropdown-submenu"><a tabindex="-1" href="#"><c:out value="${cata}" /></a>
<ul class="dropdown-menu" role="menu">

    <c:forEach var="secCategories" items="${categoryMap['cata']}">
        <c:forEach var="second" items="${secCategories}">
            <li role="presentation"><a role="menuitem"
                href="/browse?type="${fn:replace(second, ' ','+')}"><c:out
                        value="${second}" /></a></li>
        </c:forEach>
    </c:forEach>

</ul></li>
</c:forEach>

The error I get is

WARNING: Nested in javax.servlet.ServletException: javax.servlet.jsp.JspException: javax.el.PropertyNotFoundException: Could not find property [Aerial & Lifting Equipment in class java.lang.String: javax.el.PropertyNotFoundException: Could not find property [Aerial & Lifting Equipment in class java.lang.String

Where "[Aerial & Lifting Equipment" is the first key from the variable categories and set as the new variable ${cata}. As this is not working, I'm missing something on how to pass the dynamic key properly.

SOLUTION
This fixed my issue, I set the attribute types which I forgot before, and for ease of use I changed the ArrayList to a String[].

<%@attribute name="user" required="true" type="com.entity.User"%>
<%@attribute name="catagories" required="true" type="java.lang.String[]"%>
<%@attribute name="categoryMap" required="true" type="java.util.Map"%>

<c:forEach var="cata" items="${catagories}">
<li class="dropdown-submenu"><a tabindex="-1" href="#"><c:out value="${cata}" /></a>
<ul class="dropdown-menu" role="menu">
<c:forEach var="secCategories" items="${categoryMap[cata]}">
    <c:forEach var="second" items="${secCategories}">
        <li role="presentation"><a role="menuitem"
            href="/browse?type="${fn:replace(second, ' ','+')}"><c:out
                    value="${second}" /></a></li>
    </c:forEach>
</c:forEach>
</ul></li>
</c:forEach>
JWL
  • 17
  • 1
  • 6
  • Have checked your HashMap?? Is it having an ArrayList against the key Aerial & Lifting Equipment?? – Brijesh Bhatt Mar 13 '15 at 10:17
  • @alfreema `catagories=[Aerial & Lifting Equipment, Asphalt & Concrete Equipment, Attachments, Compaction Equipment, Construction Equipment, Earthmoving Equipment, Forestry & Mining Equipment]` categoryMap={Aerial & Lifting Equipment=[All Terrain Crane, Boom Lift, Forklift, Hydraulic Truck Crane, Material Handler, Personnel Lift, Rough Terrain Crane, Scissor Lift, Telehandler, Telescopic Forklift], Forestry & Mining Equipment=[Crawler Tractor, Feller Buncher, Forwarder, Harvester, Log Loader, Rock Truck, Shovel, Skidder, Wheel Dozer, Wheel Loader]} – JWL Mar 13 '15 at 17:43

4 Answers4

1

You're gonna be mad at yourself, but ....

<c:forEach var="secCategories" items="${categoryMap['cata']}">

should be

<c:forEach var="secCategories" items="${categoryMap[cata]}">

You don't want the literal string "cata" being the key, you want the value of the cata page property being the key. :)

alfreema
  • 1,308
  • 14
  • 26
  • I removed the single quotes and still get the same error, Could not find property [Aerial & Lifting Equipment in class java.lang.String – JWL Mar 13 '15 at 17:27
0

I removed the single quotes and change the categories value from ArrayList to String[]. But I also forgot to define the attribute types at the top of the page. So they were just acting like strings.

<%@attribute name="user" required="true" type="com.entity.User"%>
<%@attribute name="catagories" required="true" type="java.lang.String[]"%>
<%@attribute name="categoryMap" required="true" type="java.util.Map"%>
JWL
  • 17
  • 1
  • 6
0
<!--Iterate Map entries -->
<c:forEach items="${categoryMap}" var="entry">
         <!--For Each Entry iterate the value -->
         <!-- use ${entry.key} if you need the key -->
         <c:forEach var="second" items="${entry.value}">
            <li role="presentation"><a role="menuitem"
                href="/browse?type="${fn:replace(second, ' ','+')}"><c:out
                        value="${second}" /></a></li>
        </c:forEach>
</c:forEach>

https://stackoverflow.com/a/1835742/1356423

Community
  • 1
  • 1
Alan Hay
  • 22,665
  • 4
  • 56
  • 110
0

Try the following solution:

<c:forEach var="cata" items="${catagories}">
<li class="dropdown-submenu"><a tabindex="-1" href="#"><c:out value="${cata}" /></a>
<ul class="dropdown-menu" role="menu">

    <c:forEach var="secCategories" items="${categoryMap}">
        <c:forEach var="second" items="${secCategories}">
           <c:choose>
               <c:when test="${fn:toLowerCase(second) == fn:toLowerCase(cata)}">
                   <li role="presentation"><a role="menuitem"
                href="/browse?type="${fn:replace(second, ' ','+')}"><c:out
                        value="${second}" /></a></li>
               </c:when>
           </c:choose>

        </c:forEach>
    </c:forEach>

</ul></li>
Brijesh Bhatt
  • 3,810
  • 3
  • 18
  • 34