In you ActionForm java class, you have to define the selectedCountry instance
variable. For example
....
....
public MyForm extends ActionForm {
private String [] selectedCountry = {}; // if the option is multiple selection (check
box or multiple selection listbox)
// private String selectCountry; // if the option is single selection
(radio button or dropdown box)
// generate getter and setter method based on the above variable)
}
When Struts populates the data, it checks the selectedCountry array in your form. If
the country is found in your ActionForm, Struts automatically adds "selected" to that
item (country). You don't have to do anything as long as your ActionForm class defined
correctly.
I have done for radio button, checkbox, dropdown box, single and multiple listbox.
They work well!
Jiin-Her Lu
(816) 926-2145
>>> [EMAIL PROTECTED] 02/02/04 11:47AM >>>
How does one add selected attribute if I want one the
option to have the SELECTED attribute
--- Jiin-Her Lu <[EMAIL PROTECTED]> wrote:
> you can do as following.
> countryCollection is an ArryList with object of
> struts' LabelValueBean. The value is the country
> code and label is the country name for example.
> Once the user changes the country selection, it will
> submit the change to server so that the action can
> generate the city list based on the selected county.
> Once it's done, forward to itself. The list of city
> will be populated accordingly. If you want use
> javascript, then it's a different story.
>
> Hope this can help!
>
> <html:select property="selectedCountry" >
> <html:options collection="countryCollection"
> property="value" labelProperty="label"
> onchange="submit()" />
> </html:select>
>
> <html:select property="selectedCity" >
> <html:options collection="cityCollection"
> property="value" labelProperty="label" />
> </html:select>
>
>
>
> Jiin-Her Lu
> (816) 926-2145
>
> >>> [EMAIL PROTECTED] 02/02/04 09:49AM >>>
> Apologies for this newbie question...
>
> I have 2 selections: Country and City
> I have 2 collections in session (CityList contains a
> reference to Country)
> I don't want the user to select a City before
> selecting a Country and I want
> to display a list of Cities that relate to the
> selected Country...
>
> Can anyone please help with this code:
>
> ...
> <tr>
> <td>Country</td>
> <td>
> <html:select property="country"
> onchange="document.forms['myForm'].city.value='';
>
> document.forms['myForm'].submit();">
> <html:option value="">Select a
> country...</html:option>
> <html:options collection="CountryList"
> property="country"
> labelProperty="description" />
> </html:select>
> <font color="red"><html:errors
> property="country" /></font>
> </td>
> </tr>
> <tr>
> <td>City</td>
> <td>
> <html:select property="city">
> <html:option value="">Select a
> city...</html:option>
> <logic:iterate id="City" name="CityList"
> property="list"
> type="City">
>
<<<<<-----------------------------------------------------------------------
> ------
> <logic:equal name="City"
> property="country" value="">
> !!! This is where I'm stumped. How do I get the
> comparison to work between 2
> beans?
>
>>>>>-----------------------------------------------------------------------
> ------
> <html:option name="City" property="city"
> labelProperty="description" />
> </logic:equals >
>
> </logic:iterate>
> </html:select>
> <font color="red"><html:errors property="city"
> /></font>
> </td>
> </tr>
> ...
>
> Any help much appreciated!
> Derek
>
>
>
>
---------------------------------------------------------------------
> 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]
>
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/
---------------------------------------------------------------------
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]