开发者

Set default value of select using java in Struts 1.x

I've come across answers for Struts 2.x but none for struts 1.x.

All I need to do is select a default value on page load using 1.x of an HTML:SELECT tag that uses an optioncollector:

<html:select property="status">
  <html:optionsCollection name="statusList" label="description" value="id" />
</html:select>
开发者_运维问答

Seems simple, but I'd like to avoid using javascript for this.


Have you tried to use the value attribute on the <html:select> tag?

<html:select property="status" value="...your status choise here...">
  <html:optionsCollection name="statusList" label="description" value="id" />
</html:select>


Default select option in struts 1 behaves pretty strange. As user159088 mentioned "value" parameter is responsible for setting default value. But it works only for hardcode:

<html:select name="myForm" property="formField.enabled" title="Enabled" styleId="enabled" value="false">
    <html:option value="true">true</html:option>
    <html:option value="false">false</html:option>
</html:select>

Code snippet above works good - false value selected by default. But "formField.enabled" in value parameter doesn't work:

<html:select name="myForm" property="formField.enabled" title="Enabled" styleId="enabled" value="formField.enabled">
    <html:option value="true">true</html:option>
    <html:option value="false">false</html:option>
</html:select>

Removing value parameter works good in this case - struts check value from property parameter and select this value by default.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜