Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set default value to form:select tag in spring

Can someone tell me how to set default value in form:select tag in spring?

I have four auctions. 1) Normal 2) Reverse 3) French 4) Dutch

I am using spring's form:select and form:options tag for the same.

But now the requirement is that Normal should be selected by default.

How do I achieve this?

Thanks

like image 710
Thanos Avatar asked Dec 29 '22 01:12

Thanos


1 Answers

Try this

<form:select path="auction">
    <c:forEach items="${auctions}" var="auc" varStatus="status">
        <c:choose>
            <c:when test="${auc.id eq '1'}">
                <option value="${auc.id}" selected="true">${auc.name}</option>
            </c:when>
            <c:otherwise>
                <option value="${auc.id}">${auc.name}</option>
            </c:otherwise>
        </c:choose> 
    </c:forEach>
</form:select>
like image 81
gjman2 Avatar answered Jan 13 '23 16:01

gjman2