wood burning stoves 2.0*
The moose likes JSP and the fly likes Nested hashmap tags for dynamic pulldowns Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Nested hashmap tags for dynamic pulldowns" Watch "Nested hashmap tags for dynamic pulldowns" New topic
Author

Nested hashmap tags for dynamic pulldowns

Lee Wright
Greenhorn

Joined: Nov 29, 2004
Posts: 11
I am trying to get a page working that has two pulldowns.
The first is a static list of values held in a List and the second is a HashMap with the keys matching values of the first List array.

I can get the list to display all items in the Hash:

<html:select indexed="true" name="requestList" property="event" >
<c:forEach var="key" items="${requestForm.events}">
<option><c ut value='key=${key.key}, value=${key.value}'/></option>
</c:forEach>
</html:select>

This alone took way too much time...but now I need to limit the values to those that match a previous List box...


Help...!!
[ November 30, 2004: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

but now I need to limit the values to those that match a previous List box...


It's not clear whay you mean by this, but regardless, if there is any data filtering to be done it should be done when the collections are created rather than on-page.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Lee Wright
Greenhorn

Joined: Nov 29, 2004
Posts: 11
The problem is that the pge will have multiple lines and each line will have a different location pulldown.
I wanted to avoid having multiple copies of the lists which is why I wanted to put them into a single HashMap.

I got this far:

<html:select indexed="true" name="requestList" property="event" >
<c:forEach var="key" items="${requestForm.events}">
xx[<c ut value="${requestList.location}"></c ut>]xx

yy[<c ut value="${key.key}"></c ut>]yy
<c:if test="${requestList.location}=" + <c ut value="${key.key}"></c ut> >
<option>Matched</option>
</c:if>
<option><c ut value='key=${key.key}, value=${key.value}'/></option>
</c:forEach>
</html:select>

xx[10]xx and yy[10] are matching but not appearing as equal in my test="" clause.

Thanks

L
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

I wanted to avoid having multiple copies of the lists which is why I wanted to put them into a single HashMap.


Why? If they are distinct abstractions, why mash them all together to be sorted out later?

By the way, if you click the 'disable smilies' box on your posts, your tags will look less surprised.
Lee Wright
Greenhorn

Joined: Nov 29, 2004
Posts: 11
Its because the list is dynamic from a database lookup.
This creates then populates an Array of possible options, then the ID values for each of these are used as the key for the dynamic HashMap.
This HashMap then contains:

[ 1 ] [ Array of LabelValueBeans ]
[ 2 ] [ Array of LabelValueBeans ]
[ 3 ] [ Array of LabelValueBeans ] ... etc..

When item with id 1 is selected I want the secondary pull-down to display the ArrayList of LabelValueBeans.

Hope that makes sense..
Lee Wright
Greenhorn

Joined: Nov 29, 2004
Posts: 11
I think I found the solution to my problem. I've posted it just incase anyone else is facing similar problems doing dynamic matching in JSTL:

<html:form action="iterate.do" method="POST">

<html:select onchange="document.forms[0].submit();" name="selectOne">

<c:forEach items="${iterateActionForm.listIterator}" var="list">
<option value='<cut value="${list.value}"></cut>'> <cut value="${list.label}"></cut></option>
</c:forEach>
</c:set>

</select>

<select name="selectTwo">
<c:forEach items="${iterateActionForm.complexIterator}" var="keys">
<c:choose>
<c:when test="${keys.key == iterateActionForm.selectOne}">
<c:forEach items="${keys.value}" var="bean">
<option value="<cut value='${bean.value}'/>">
<cut value="${bean.label}"></cut>
</option>
</c:forEach>
</c:when>
</c:choose>
</c:forEach>
</select>

The key here is the test clause is using a value set by the previous select html tag.

Lee
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Nested hashmap tags for dynamic pulldowns
 
Similar Threads
Combo box internationalization
key from HashMap
Iterating over Map using JSTL
List of Lists &lt;html:select&gt;
html:select indexed - idexes the formbean i.s.o. the property