You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dylan Stamat <dy...@gmail.com> on 2005/09/15 00:34:59 UTC
LabelValueBean in a Form
I'm using a LabelValueBean, as I need to have a "name" be diplayed, and a
"value" be reported back to the form.
I have no problems creating a List of LabelValueBean's, setting them into
the request like so:
request.setAttribute("myLVBList", myLVBList);
... and outputting them on the .jsp like so:
<html:options collection="myLVBList" property="value"
labelProperty="label"/>
However, I'd rather put this list into my Form, and not in the Request.
I fiddled around with html:options and html:optionsCollection trying a slew
of different combinations using the Struts HTML docs as a reference, but no
luck.
Is this even possible ?
Thanks !
==
Dylan
Re: LabelValueBean in a Form
Posted by Kishore Senji <ki...@gmail.com>.
It is possible. Have a method on your ActionForm which returns a
java.util.Collection of org.apache.struts.util.LabelValueBean's and use it
using <html:optionsCollection/> in the jsp
For eg:
public Collection getMyLVBList() {
Collection options = new ArrayList();
options.add(new LabelValueBean(label, value));
// add more options
return options;
}
<html:select property="selectProperty">
<html:optionsCollection property="myLVBList"/>
</html:select>
On 9/14/05, Dylan Stamat <dy...@gmail.com> wrote:
>
> I'm using a LabelValueBean, as I need to have a "name" be diplayed, and a
> "value" be reported back to the form.
>
> I have no problems creating a List of LabelValueBean's, setting them into
> the request like so:
> request.setAttribute("myLVBList", myLVBList);
>
> ... and outputting them on the .jsp like so:
> <html:options collection="myLVBList" property="value"
> labelProperty="label"/>
>
> However, I'd rather put this list into my Form, and not in the Request.
> I fiddled around with html:options and html:optionsCollection trying a
> slew
> of different combinations using the Struts HTML docs as a reference, but
> no
> luck.
>
> Is this even possible ?
>
> Thanks !
> ==
> Dylan
>
>