You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Bard A. Evjen" <ba...@operamail.com> on 2003/07/25 14:49:03 UTC

How can I get a value and a name that is different on a html:options collection?

I have a Form class:

public Collection getMyMonthList() {
  myMonthList = new Vector();
  Calendar cal = Calendar.getInstance();
  cal.setTime(new Date(01012003));
  for (int i = 1; i < 13; i++) {
    String label = monthListFormat.format(zeroTime(cal.getTime(), 
Calendar.MONTH, i));
    LabelValueBean labelBean = new LabelValueBean("i", label);
    myMonthList.add(labelBean);
  }
  return myMonthList;
}

and a jsp-file with:

<html:select size="1" property="reportDateMonth">
  <html:options property="myMonthList" labelProperty="myMonthList"/>
</html:select>

But this returns

LabelValueBean[i,February]
LabelValueBean[i,March]
LabelValueBean[i,April]
LabelValueBean[i,May]
LabelValueBean[i,June]
LabelValueBean[i,July]
LabelValueBean[i,August]
LabelValueBean[i,September]
LabelValueBean[i,October]
LabelValueBean[i,November]
LabelValueBean[i,Desember]
LabelValueBean[i,January]

I want to display the name (eg. january) and the value in the option tag 
(eg. 1).

What have I done wrong?

Cheers,
Bard A.


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


RE: How can I get a value and a name that is different on a html:options collection?

Posted by Robert Taylor <rt...@mulework.com>.
>     LabelValueBean labelBean = new LabelValueBean("i", label);
Change to
>     LabelValueBean labelBean = new LabelValueBean(String.valueOf(i),
label);

robert

> -----Original Message-----
> From: Bard A. Evjen [mailto:bardevjen@operamail.com]
> Sent: Friday, July 25, 2003 8:49 AM
> To: struts-user@jakarta.apache.org
> Subject: How can I get a value and a name that is different on a
> html:options collection?
>
>
> I have a Form class:
>
> public Collection getMyMonthList() {
>   myMonthList = new Vector();
>   Calendar cal = Calendar.getInstance();
>   cal.setTime(new Date(01012003));
>   for (int i = 1; i < 13; i++) {
>     String label = monthListFormat.format(zeroTime(cal.getTime(),
> Calendar.MONTH, i));
>     LabelValueBean labelBean = new LabelValueBean("i", label);
>     myMonthList.add(labelBean);
>   }
>   return myMonthList;
> }
>
> and a jsp-file with:
>
> <html:select size="1" property="reportDateMonth">
>   <html:options property="myMonthList" labelProperty="myMonthList"/>
> </html:select>
>
> But this returns
>
> LabelValueBean[i,February]
> LabelValueBean[i,March]
> LabelValueBean[i,April]
> LabelValueBean[i,May]
> LabelValueBean[i,June]
> LabelValueBean[i,July]
> LabelValueBean[i,August]
> LabelValueBean[i,September]
> LabelValueBean[i,October]
> LabelValueBean[i,November]
> LabelValueBean[i,Desember]
> LabelValueBean[i,January]
>
> I want to display the name (eg. january) and the value in the option tag
> (eg. 1).
>
> What have I done wrong?
>
> Cheers,
> Bard A.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


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