You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Lars Bergström <la...@systeam.se> on 2003/09/18 13:46:17 UTC
Ted Husted: html:optionsCollection & Map
Dear Ted,
I am trying to get my html:optionsCollection to work with a TreeMap. I
don't
know if this is possible but on the Struts API page for the class
OptionsCollectionTag I read the following:
"The collection may be an array of objects, a Collection, an
Enumeration, an
Iterator, or a Map."
(
http://jakarta.apache.org/struts/api/org/apache/struts/taglib/html/Opti
onsCollectionTag.html)
Since TreeMap implements SortedMap which is a subinterface of Map,
TreeMap
should work fine, right?
However, when the page is loaded I get the folloing error text:
"HTTP ERROR: 500 No getter method available for property label for bean
under
name 1=LabelValueBean[Label 1, Value 1]"
Can anyone explain this error message? This seems strange to me.
The returntype in my ActionFormBean is TreeMap and the code snippet
where I
build up the TreeMap is like this:
eventGroups = new TreeMap();
eventGroups.put( new String( "1" ),
new LabelValueBean( "Label 1",
"Value 1" ) );
eventGroups.put( new String( "2" ),
new LabelValueBean( "Label 2",
"Value 2" ) );
eventGroups.put( new String( "3" ),
new LabelValueBean( "Label 3",
"Value 3" ) );
((EventGroupBean)form).setEventGroups( eventGroups );
(
Best regards
Lasse
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Ted Husted: html:optionsCollection & Map
Posted by Joe Germuska <Jo...@Germuska.com>.
From looking at the source, when given a
java.util.Map, OptionsCollectionTag iterates
through the entrySet, not the keySet or the
values collection. Therefore, when the "label"
and "value" of each bean is dereferenced, the
properties must be relative to a Map.Entry bean.
It looks as if you wrote your tag assuming that
it would iterate through the values collection.
Given the signature of Map.Entry, you could
dereference a nested property beginning with
"value" -- that is, something like
<html:optionsCollection name="yourMapName"
label="value.label" value="value.value" .../>
Joe
and where
At 13:46 +0200 9/18/03, Lars Bergström wrote:
>Dear Ted,
>
>I am trying to get my html:optionsCollection to work with a TreeMap. I
>don't
>know if this is possible but on the Struts API page for the class
>OptionsCollectionTag I read the following:
>
>"The collection may be an array of objects, a Collection, an
>Enumeration, an
>Iterator, or a Map."
>(
>http://jakarta.apache.org/struts/api/org/apache/struts/taglib/html/Opti
>onsCollectionTag.html)
>
>
>Since TreeMap implements SortedMap which is a subinterface of Map,
>TreeMap
>should work fine, right?
>
>However, when the page is loaded I get the folloing error text:
>"HTTP ERROR: 500 No getter method available for property label for bean
>under
>name 1=LabelValueBean[Label 1, Value 1]"
>
>Can anyone explain this error message? This seems strange to me.
>
>The returntype in my ActionFormBean is TreeMap and the code snippet
>where I
>build up the TreeMap is like this:
>
>eventGroups = new TreeMap();
>eventGroups.put( new String( "1" ),
> new LabelValueBean( "Label 1",
> "Value 1" ) );
>eventGroups.put( new String( "2" ),
> new LabelValueBean( "Label 2",
> "Value 2" ) );
>eventGroups.put( new String( "3" ),
> new LabelValueBean( "Label 3",
> "Value 3" ) );
>((EventGroupBean)form).setEventGroups( eventGroups );
>(
>
>
>Best regards
>
>Lasse
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
--
--
Joe Germuska
Joe@Germuska.com
http://blog.germuska.com
"If nature worked that way, the universe would crash all the time."
--Jaron Lanier
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org