Issue
I’m using Spring 3.2.11.RELEASE. How do I include a data attribute in my form:option ? I have
<form:select path=“myField” cssClass=“myField”>
<form:option value="" label="Select Option” />
<c:forEach items="${parentOrgList}" var="org">
<form:option value="${org.id}" data-url="${org.urlAsString}">${org.name}</form:option>
</c:forEach>
</form:select>
but when the options are rendered, the “data-url” is ignored and the option is rendered like so
<option value="5C898CF6054C49BC8B0DE3C4FDE795CC">My option</option>
How do I get my data attributes included?
Solution
As far as I know, there is not such an atribute in spring form tld for option tag. "Appendix H. spring-form.tld - Option tag"
If you really need that, you may subclass org.springframework.web.servlet.tags.form.OptionTag to support this atribute so it can display the way you want and publish it in one custom tld.
Or maybe you could just include it as plain html option tag instead of using spring-form tld tag in this case.
<c:forEach items="${parentOrgList}" var="org">
<option value="${org.id}" data-url="${org.urlAsString}">${org.name}</option>
</c:forEach>
Answered By - jlumietu
Answer Checked By - David Marino (JavaFixing Volunteer)