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 tried:
<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>
But that gives me a big error. How can I make the itemLabels show lastname, firstname?
I don't think so. Either have a getFullName()
getter in your object returning the concatenation of last and first names, or display the options one by one, in a loop:
<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>
With concatenation performed by user.getFullName()
:
<form:select path="user"
items="${user.userList}"
itemValue="id"
itemLabel="fullName">
</form:select>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With