본문 바로가기
Developer/HTML & JSP & CSS

[Spring] Selectbox 자유롭게 쓰기

by 순수한소년 2020. 7. 29.
728x90
반응형

출처

https://stackoverflow.com/questions/7143738/is-it-possible-to-use-multiple-params-in-the-itemlabel-of-a-formselect-formopt

 

Is it possible to use multiple params in the itemLabel of a form:select/form:option

I'm using Spring. I've got a JSP with a form:select in it displaying the list of users. In this situation the username or id won't mean much to the user so I need to show firstname lastname. I've

stackoverflow.com

기존

1
2
3
4
<form:select id="userSelect" name="userId" path="user.id">
    <option value="">Select to Edit</option>
    <form:options items="${user.userList}" itemValue="id" itemLabel="lastname firstname" />
</form:select>
cs

변경

1
2
3
4
5
6
7
8
<form:select id="userSelect" name="userId" path="user.id">
    <option value="">Select to Edit</option>
    <c:forEach var="theUser" items="${user.userList}">
        <form:option value="${theUser.id}">
            <c:out value="${theUser.lastname} ${theUser.firstname}"/>
        </form:option>
    </c:forEach>
</form:select>
cs
반응형