You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Henrique VIECILI <vi...@softplan.com.br> on 2004/06/16 13:49:36 UTC

Re:[SOLVED] using java.util.Map

Well, I was using a TreeMap and put it straight to the application scope from a plugin, but what i needed was some collection in the scope, then i did :

Map states = new TreeMap();
states.put(...);

getServletContext().setAttribute("states",states.entrySet());

The entrySet() returns a Set (collection) of Map.Entry wich is like a bean, with methods getKey() and getValue(), so i can use it normally with <html:options>.

Thank you all for the contributions,

Henrique Viecili
  ----- Original Message ----- 
  From: Ron Grabowski 
  To: struts 
  Sent: Wednesday, June 16, 2004 12:11 AM
  Subject: Re: <html:options> using java.util.Map


  > From: "Barnett, Brian W." <bb...@scholarinc.com>
  > To: 'Struts Users Mailing List'
  > <us...@struts.apache.org>
  > Subject: RE: <html:options> using java.util.Map
  > Date: Tue, 15 Jun 2004 13:44:00 -0500
  > 
  > If you don't use the collection attribute, and you
  > want different values and
  > labels in the list, you need to define two separate
  > collections, one for the
  > values and one for the labels.
  > 
  > ArrayList statesValues = new ArrayList();
  > statesValues.add("RS");
  > statesValues.add("SC");
  > statesValues.add("PR");
  > ArrayList statesLabels = new ArrayList();
  > statesLabels.add("Rio Grande do Sul");
  > statesLabels.add("Santa Catarina");
  > statesLabels.add("ParanĂ¡");

  Or you could use a LabelValueBean:

   LabelValueBean[] schoolIds = new LabelValueBean {
    new LabelValueBean("Rio Grande do Sul","RS"),
    new LabelValueBean("Santa Catarina","SC"),
    new LabelValueBean("Parana","PR")
   };

  If you make schoolIds a property on your ActionForm
  you're able to do this:

   <html:select property="schoolId">
    <html:options property="schoolIds">
   </html:select>

  I've always thought naming the options list the plural
  of the property I'm trying to set is the most straight
  forward naming convention: the user is selecting a
  schoolId from a list of valid schoolIds.

  If you still want to us a Map, I would use a
  LinkedHashMap so the order in which you add the
  elements is the same order in which they print out.

  - Ron



  __________________________________
  Do you Yahoo!?
  Yahoo! Mail Address AutoComplete - You start. We finish.
  http://promotions.yahoo.com/new_mail 

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