简体   繁体   中英

How can I set the default value for an <html:optionsCollection> element?

There is a similar question on this site asking for how to set the default vaule for an HTML object .

This relies on setting a "value" tag for an individually-listed <option> , but I am using an optionsCollection , with a pre-set list of options.

<html:select property="optionsList">
    <html:optionsCollection name="lutOptions"/>
</html:select>

I tried indicating the desired option to be selected , but it doesn't appear to work. Instead, it just creates a new option for the list at the bottom.

<option selected="selected">desired option</option>

How do I set one of the options from the lutOptions list to be the default option for my optionsCollection object?

Maybe this link can help you.

http://www.coderanch.com/t/54537/Struts/Set-default-html-select

As mentioned in the link, you can set the ActionForm bean property to the appropriate value. There are three ways to set the ActionForm bean property:

  1. You can set it in an Action class that forwards to the JSP
  2. You can set it in the JSP itself with a <c:set> tag
  3. You can set this value in the reset() method of the ActionForm bean

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM