Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get Spring's form:option to not ignore my data attributes?

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?

like image 219
Dave Avatar asked Nov 29 '25 15:11

Dave


1 Answers

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>
like image 111
jlumietu Avatar answered Dec 01 '25 05:12

jlumietu