Ok, thanks. I just thought that could be some way of doing this with java.util.Map 
instead of any collection.

Henrique Viecili
  ----- Original Message ----- 
  From: Barnett, Brian W. 
  To: 'Struts Users Mailing List' 
  Sent: Tuesday, June 15, 2004 3:44 PM
  Subject: RE: <html:options> using java.util.Map


  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á");

  Next, put these ArrayLists in scope (I put them in my formbean):
  myForm.setStatesValues(statesValues);
  myForm.setStatesLabels(statesLabels);

  And then reference them like this in your jsp:

  <html:select name="myForm" property="someProperty">
    <html:options name=" myForm" property="statesValues" labelName="myForm"
  labelProperty="statesLabels"/> 
  </html:select>

  This worked for me, giving me html as you suggested you wanted.

  Brian Barnett

  -----Original Message-----
  From: Henrique VIECILI [mailto:[EMAIL PROTECTED] 
  Sent: Tuesday, June 15, 2004 12:12 PM
  To: Struts Users Mailing List
  Subject: Re: <html:options> using java.util.Map

  Ok, but probably 'allSchools' is actually a collection of beans that have
  getSchoolId() and getSchoolName() methods, right?!

  What I have is a java.util.Map like this:

  Map states = new HashMap();
  states.put("RS","Rio Grande do Sul");
  states.put("SC","Santa Catarina");
  states.put("PR","Paraná");

  and i want to render something like this on my html

  <select name="states">
    <option value="RS">Rio Grande do Sul</option>
    <option value="SC">Santa Catarina</option>
    <option value="PR">Paraná</option>
  </select>

  I guess that is it,
  Henrique Viecili
    ----- Original Message ----- 
    From: Barnett, Brian W. 
    To: 'Struts Users Mailing List' 
    Sent: Tuesday, June 15, 2004 2:57 PM
    Subject: RE: <html:options> using java.util.Map


    Here is an example that we have used and it works:

    <html:select property="schoolId">
    <html:options collection="allSchools" 
    property="schoolId" labelProperty="schoolName"/>
    </html:select>

    -----Original Message-----
    From: Henrique VIECILI [mailto:[EMAIL PROTECTED] 
    Sent: Tuesday, June 15, 2004 12:00 PM
    To: Struts Users Mailing List
    Subject: <html:options> using java.util.Map

    Does anyone know howto use the <html:options> tag with the values and
  label
    inside a Map?

    I´ve tried this:

    <html:options name="myMap" property="key" labelName="myMap"
    labelProperty="value"/>

    but it didnt work...

    Any sugestions?!

    Henrique Viecili

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: [EMAIL PROTECTED]
    For additional commands, e-mail: [EMAIL PROTECTED]

  ---------------------------------------------------------------------
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to