struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joe Barefoot" <Joe.Baref...@motiva.com>
Subject RE: HELP! html:options with a hashmap
Date Thu, 12 Sep 2002 21:32:08 GMT
Cool.  Glad it works.  You could probably do away with the scriplet by adding another property
getter in your action form though, call it getAllUserRolesKeysAsCollection, or some such title,
and just return myHashMap.entrySet().  To be honest, I've never used a Hashmap like this in
Struts.  I've always used an ArrayList for the Collection, populated with KeyValuePair objects
(with key/value getters).  Good to know it can be done.

peace,
joe


> -----Original Message-----
> From: Michael Lee [mailto:mleejr@hotmail.com]
> Sent: Thursday, September 12, 2002 1:42 PM
> To: Struts Users Mailing List
> Subject: Re: HELP! html:options with a hashmap
> 
> 
> Wow! This worked like a champ! What I was doing was actually 
> not what you
> were saying. What I was doing was much more complicated. This is MUCH
> cleaner.
> 
> The thing I didn't know about we're the "key" and "value" 
> names. I found the
> "value" one but didn't understand exactly how to use it. I 
> found the only
> pertinent example on some spanish web site. I tried to figure 
> out what they
> were doing but to no avail. (Hey Marc, how's that for well 
> documented?)
> 
> Anyway, here's the code for all to enjoy;
> ...
> ***********This section gets the HashMap with the 
> Lookup.getData() method
> then calls .entrySet()*********
> <%
>     pageContext.setAttribute("allUserRolesKeys",
> Lookup.getData(Constant.USER.USER_ROLES).entrySet());
> %>
> ....
>     <html:select property="userRole" size="1">
>       <html:options collection="allUserRolesKeys" property="key"
> labelProperty="value"/>
>     </html:select>
> 
> Thanks again Joe,
> Mike
> 
> ----- Original Message -----
> From: "Joe Barefoot" <Joe.Barefoot@motiva.com>
> To: "Struts Users Mailing List" <struts-user@jakarta.apache.org>
> Sent: Thursday, September 12, 2002 3:51 PM
> Subject: RE: HELP! html:options with a hashmap
> 
> 
> You don't see an example because html:options expects a 
> *Collection*, not a
> Map.  I have no idea if the tag works with a Map, but it 
> probably doesn't
> because it expects a Collection object.  If you want to use a Map
> implementation (like HashMap), then your property getter should return
> myHashMap.entrySet() and you should set these attributes in the
> <html:options tag>: property="value" labelProperty="key".  
> Something like
> that.
> 
> http://java.sun.com/j2se/1.3/docs/api/index.html
> 
> 
> Struts javadocs are quite verbose:
> 
> http://jakarta.apache.org/struts/doc-1.0.2/api/index.html
> 
> Click on any of the taglib packages in the top left frame, 
> then the package
> name in the bottom left frame, then the "Description" link 
> that comes up in
> the right frame.  Gets you descriptions of any tag.  You can 
> reach these
> throught the Struts site as well.
> 
> peace,
> Joe
> 
> 
> 
> > -----Original Message-----
> > From: Michael Lee [mailto:mleejr@hotmail.com]
> > Sent: Thursday, September 12, 2002 10:53 AM
> > To: Struts Users Mailing List
> > Subject: HELP! html:options with a hashmap
> >
> >
> > I posted this before but haven't heard anything. Thought I
> > would put up the error message too. What name do I put for
> > name? The examples don't use a hashmap (seems logical for
> > 'options'). When I put name it does the name and value. I
> > want it to put the name under name and value under value, not
> > both in the drop down.
> >
> > I want to populate an <html:select> with data from a Map
> > (HashMap). I have
> >
> > ...
> > <% pageContext.setAttribute("allUserRoles",
> > Lookup.getData(Constant.USER.USER_ROLES)); %>
> > ...
> >     <bean:message key="prompt.user.role"/>
> >     <html:select property="userRole" size="1">
> >       <html:options collection="allUserRoles"/>
> >     </html:select>
> >
> > I don't see an example in the struts-exercise-taglib.war
> > under html:select
> > It is vector or Object[].
> > Ideas?
> > thanks,
> > Mike
> >
> > <Sep 12, 2002 1:48:29 PM EDT> <Error> <HTTP>
> > <[WebAppServletContext(2285117,rece
> > iptsplus,/receiptsplus)] Servlet failed with Exception
> > java.lang.IllegalArgumentException: No name specified
> >         at
> > 
> org.apache.struts.util.PropertyUtils.getNestedProperty(PropertyUtils.
> > java:405)
> >         at
> > 
> org.apache.struts.util.PropertyUtils.getProperty(PropertyUtils.java:4
> > 53)
> >         at
> > 
> org.apache.struts.taglib.html.OptionsTag.doEndTag(OptionsTag.java:230
> > )
> >         at
> > jsp_servlet.__create_user._jspService(__create_user.java:395)
> >         at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
> >
> 
> --
> To unsubscribe, e-mail:
> <mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:struts-user-help@jakarta.apache.org>
> 
> 
> --
> To unsubscribe, e-mail:   
<mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message