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>