Meaningless Drivel is fun!*
The moose likes Spring and the fly likes Help needed to indicate " title="" /> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Help needed to indicate "selected" for <form:select> <form:option/>" Watch "Help needed to indicate "selected" for <form:select> <form:option/>" New topic
Author

Help needed to indicate "selected" for <form:select> <form:option/>

laura mccord
Ranch Hand

Joined: Feb 10, 2009
Posts: 108
Hi Everyone,

I can't figure out how to show that a value is "selected" on an option list. I know that "selected" is not supported and that the "path" should be bound to the value. I'm not sure what this entirely means but I thought in my controller if I set the value of the "path" it would automagically be set within the form. But, because I am doing something a little less than normal I'm figuring that I have something messed up. This is what I have do far:


Here's a snippet of my controller.



Here is my jsp page:
The path "movieid" corresponds to the MovieTimeslot id for the MovieTimeslot object which contains the timeslotid, movieid, showtime, theaterId. So, I don't know how to show that one of my movie options is "selected" based on my controller which finds the movie object if an editId exists.


Any suggestions would be appreciated.

Thanks.
laura mccord
Ranch Hand

Joined: Feb 10, 2009
Posts: 108
What I found worked for me was to change things around in my jsp nd use the <spring:bind> tag instead of <form> tags

<spring:bind path="movieid">
<select name="movieid">
<c:forEach items='${movies}' var='movie'>
<c:choose>
<c:when test="${movie.id eq timeslotid}">
<option value="${movie.id}" selected="true">${movie.title}</option>
</c:when>
<ctherwise>
<option value="${movie.id}">${movie.title}</option>
</ctherwise>
</c:choose>
</c:forEach>
</select>
</spring:bind>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help needed to indicate "selected" for <form:select> <form:option/>