Struts: HTML Option Selected?

well actually picture well actually · Aug 31, 2011 · Viewed 13.9k times · Source

In struts, it seems there is no "selected" option. The HTML option tag has a selected attribute such that you can do:

<option selected="selected">Some Option</option>

and that option will be automatically selected. Is there a way to do this in struts? It seems that in struts, its randomly auto-selected one my options for a reason I don't understand and I would like to be able to specify which option should be auto selected.

Answer

user159088 picture user159088 · Sep 1, 2011

In Struts this is done in the <html:select> tag and not in the <html:option> like for the the case of plain HTML option.

The value attribute of the <html:select> tag is used to compare against each <html:option> value and marking it as selected if a match is found.