简体   繁体   English

如何设置 <html:optionsCollection> 元件?

[英]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 . 这个站点上有一个类似的问题,询问如何为HTML对象设置默认值

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. 这依赖于为单独列出的<option>设置"value"标签,但是我使用的是optionsCollection ,其中包含选项的预设列表。

<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. 我试图说明所需的optionselected ,但它似乎没有工作。 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? 如何将lutOptions列表中的选项之一设置为optionsCollection对象的默认选项?

Maybe this link can help you. 也许此链接可以为您提供帮助。

http://www.coderanch.com/t/54537/Struts/Set-default-html-select 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. 如链接中所述,您可以将ActionForm bean属性设置为适当的值。 There are three ways to set the ActionForm bean property: 可以通过三种方式设置ActionForm bean属性:

  1. You can set it in an Action class that forwards to the JSP 您可以在转发到JSP的Action类中进行设置
  2. You can set it in the JSP itself with a <c:set> tag 您可以使用<c:set>标记在JSP本身中进行<c:set>
  3. You can set this value in the reset() method of the ActionForm bean 您可以在ActionForm bean的reset()方法中设置此值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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