As far as I know, you cannot put the main tag inside the spring tag as you tried
<form:input ... <c:if test="${autofocus==true}">autofocus</c:if> />
you can insert jstl expressions into the attribute value of the spring tag, but they will not help you, since html5 checks for autofocus.
<s:set var="autofocusVal" value=""/> <c:if test="${autofocus}"> <s:set var="autofocusVal" value="autofocus"/> </c:if> <form:input autofocus="${autofocusVal}" />
but you can do something like:
<c:choose> <c:when test="${autofocus}"> <form:input autofocus="autofocus" /> </c:when> <c:otherwise> <form:input /> </c:otherwise> </c:choose>
which is really verbose and difficult, especially if you have several attributes that you want to add.
Another crap workaround is to set the data-xxx attribute to tag the tags with autofocus, and use javascript to change the html by adding the autofocus attribute, where data-autofocus = "true":
<form:input data-autofocus="${autofocus}" />
And a more elegant way to do this (I can think now) is to expand this tag with the attributes you want to add, as explained here: fooobar.com/questions/1450703 / ...
source share