Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

jstl c:choose & c:when not working

843838Sep 8 2006 — edited Sep 11 2006
Hi,

I have a select dropdown menu on my JSP page that when the page loads, I would like the value in a bean passed to the page to be the choice selected in the dropdown menu. The user is free to change this value to something else in our app, but initially, it should be showing what was retrieved from the database. Here's the JSTL I'm using for this select tag and it's not working.

<select name="state">
<c:forEach items="${states}" var="state">
<option value="<c:out value="${state}" />"
<c:choose><c:when test="${state == detailsBean.state}"> selected="selected"</c:when>
<c:when test="${state == 'PA'}"> selected="selected"</c:when></c:choose>><c:out value="${state}"/></option>
</c:forEach>
</select>

All the select tag is is a list of the two-character state abbreviations. The detailsBean state field, in my test, was set to "MA", yet "PA" was showing as the state in the dropdown. What would be wrong with my first test clause that it's not working? Help would be appreciated, I'm new to JSTL.

Thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 9 2006
Added on Sep 8 2006
5 comments
815 views