You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ted Husted <ne...@husted.com> on 2001/01/27 22:24:54 UTC
Nested Collection with Options Tag
This works just peachy:
<bean:define id="salesYearsList" name="fruitSalesForm"
property="salesYearsList" />
<html:form action="fruitSales.do">
<html:select property="year">
<html:options collection="salesYearsList" property="value"
labelProperty="label"/>
</html:select>
Where salesYearsList is an ArrayList of LabelValueBeans (from the
trusty Example application).
The documentation (damn, someone's reading it again ;-) for options
mentions
"Only property is specified - The value of this attribute is the name
of a property of the ActionForm bean associated with our form, which
will return the collection"
Since my collection of LabelValueBeans is a property of the ActionForm
bean, I gave this a whirl, but
<html:options property="salesYearsList" labelProperty="label"/>
complained
"javax.servlet.jsp.JspException: No getter method available for
property label for bean under name null"
and
<html:options property="salesYearsList" />
brought
java.lang.ClassCastException
at
org.apache.struts.taglib.html.OptionsTag.doEndTag(OptionsTag.java,
Compiled Code)
at
_jsp._husted_22dcoreservlets_22djdbc._fruitSales__jsp._jspService(_fruit
Sales__jsp.java, Compiled Code)
Is there a way to get html:options to use my LabelValueBeans directly?
-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel 716 425-0252; Fax 716 223-2506.
-- http://www.husted.com/about/struts/
Re: Nested Collection with Options Tag
Posted by Michael Mok <mo...@iprimus.com.au>.
Ted
A workaround is to make your collections available as a page context and
then apply it to your select tag in the form.
eg in TeaTimeJ (* dbTableColumnTypes list is retrieved from the database
when the database servlet is initailised).
On the top of the page
<bean:define id="dbTableColumnTypes" name="database.servlet"
property="dbTableColumnTypes" scope="application"/>
In the form ...
<html:select name="element" property="ColumnTypeName" value="ColumnType">
<html:options collection="dbTableColumnTypes" property="value"
labelProperty="label"/>
</html:select>
Regards
Michael Mok
www.webappcabaret.com/teatimej
----- Original Message -----
From: "Ted Husted" <ne...@husted.com>
To: "Struts List" <st...@jakarta.apache.org>
Sent: Sunday, January 28, 2001 5:24 AM
Subject: Nested Collection with Options Tag
> This works just peachy:
>
> <bean:define id="salesYearsList" name="fruitSalesForm"
> property="salesYearsList" />
> <html:form action="fruitSales.do">
> <html:select property="year">
> <html:options collection="salesYearsList" property="value"
> labelProperty="label"/>
> </html:select>
>
> Where salesYearsList is an ArrayList of LabelValueBeans (from the
> trusty Example application).
>
> The documentation (damn, someone's reading it again ;-) for options
> mentions
>
> "Only property is specified - The value of this attribute is the name
> of a property of the ActionForm bean associated with our form, which
> will return the collection"
>
> Since my collection of LabelValueBeans is a property of the ActionForm
> bean, I gave this a whirl, but
>
> <html:options property="salesYearsList" labelProperty="label"/>
>
> complained
>
> "javax.servlet.jsp.JspException: No getter method available for
> property label for bean under name null"
>
> and
>
> <html:options property="salesYearsList" />
>
> brought
>
> java.lang.ClassCastException
> at
> org.apache.struts.taglib.html.OptionsTag.doEndTag(OptionsTag.java,
> Compiled Code)
> at
> _jsp._husted_22dcoreservlets_22djdbc._fruitSales__jsp._jspService(_fruit
> Sales__jsp.java, Compiled Code)
>
> Is there a way to get html:options to use my LabelValueBeans directly?
>
> -- Ted Husted, Husted dot Com, Fairport NY USA.
> -- Custom Software ~ Technical Services.
> -- Tel 716 425-0252; Fax 716 223-2506.
> -- http://www.husted.com/about/struts/
>
>