struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Martin <>
Subject RE: Map backed ActionForm, and jstl expression language
Date Fri, 02 Jul 2004 13:15:33 GMT
Hi Bill,

Many thanks for your response, I think I got bogged down the email... It was
also late for me, so couldn't put the problem succinctly, but after a few
hours sleep it became clearer... What I was trying to do was retrieve a
value from the map-backed hash map to get a default value for a drop down
list (a html:select tag use), and the property name of the dropdown to be
retrieved is taken from another bean...

In essence the jsp becomes, 

	    <td align="left" width="25%" height="25"><font class="table">
	      <bean:define id="ht" property="hmOfLists" name="dao"/>
	      	<logic:iterate id="element" name="ht">
	      	<bean:define id="filterName" property="key" name="element"/>
	      		String props = "value(" +
pageContext.getAttribute("filterName") + ")";
	      	<html:select property="<%= props %>">
		    	<html:optionsCollection name="element"

where dropdown label/values are stored in array lists that are in turn
stored in a hashmap contained in the bean "dao". The FormBean contains a
hashmap that is accessed via setValue/getValue methods. This dynamically
produces dropdowns at runtime, with default parameters defined by the
mapbacked action form.

I was trying to use jstl stuff for dynamically setting the props string and
failing... Hope it didn't make your night much later.


-----Original Message-----
From: Bill Siggelkow [] 
Sent: 02 July 2004 04:49
Subject: Re: Map backed ActionForm, and jstl expression language

John, I apologize -- it' late and I am tired but I was having a little 
trouble following your post ... however, if you have a map-backed form 
(property) that you want to expose to JSTL you will need to expose the 
Map itself in a getter.

Map getValuesMap() { return values; }

Then you can access the values by key in JSTL as

<c:out value="${myForm.valuesMap.theKey}"/> ... translates to


or the key can be dynamic ...

<c:set var="keyVal" value="foo"/>
<c:out value="${myForm.valuesMap[keyVal]}"/> ... translates to


HTH ... Bill Siggelkow

John Martin wrote:
> Hi all,
> Any help on the following problem would be most appreciated.
> What i am trying to do is produce a report of data in tabular form 
> with filters that will reduce the report set. There can be 100's of 
> different reports but by passing in a report id to a database the 
> query, filters, columns and row values can be determined.
> So i use a map backed action form for the filter property and there 
> values, this contains the methods
>   public void setValue(String key, Object value) {
>         values.put(key, value);
>     }
>     public Object getValue(String key) {
>         return values.get(key);
>     }
> For example, i want the first filter to have a value of 1, so i 
> setValue("filter1","1") and the second filter to be value 2 
> (setValue("filter1","1")).
> Now i populate another bean with the filter labels and values, that 
> gets stored in the request. These are filter lists are stored as array
lists in a hashmap with the the key, being the filter property, in this case
"filter1" and "filter2".
> So in the jsp i write
>       <c:forEach items="${dao.hmOfLists}" var="list">
>        <c:set var="props" value="${list.key}"/>
>        <c:set var="values" value="${list.value}"/>
>       <html-el:select property="${props}" value="">
>         <html:options collection="values" property="value"
>       </html-el:select>
>       </c:forEach>
> this gets me the all the filters that have been stored in the hashmap 
> from the object "dao" via the property hmOfLists, with the key in the 
> hashmap being the filter property. However, i want to set the defaults 
> on the filters via the map backed action form, but if i write 
> <html-el:select property="${props}" >, i get an error of "No getter 
> method available for property filter2......etc". So i try an access 
> the value, in the html-el:select using the expression 
> value="${testForm.props}", but this shouldn't (and doesn't work) as 
> label is actually the variable props from the hashmap, not the 
> property props from the testForm. How i can i make it use the var 
> props instead of the string literal, in order to determine the 
> property to retrieve from the map based action form ?
> Thanks,
> John

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message