0

How to compare the strings in JSP EL. I tried to do

<select name="groupa" style="width: 170px">
   <option value ="-1">no group</option>
 <c:forEach var="gr" items="${sessionScope['entrantsAcceptor'].groups}">
  <option value="${gr.idGroup}" <c:if test="${gr.code == param.group}">checked</c:if> >${gr.code}</option>
 </c:forEach>
 </select>

But it doesn't work(there are no any checked in options of select(though I pass correct argument)). Also I have tried to do

${gr.code eq param.group}

but it also has no effect

maks
  • 5,911
  • 17
  • 79
  • 123
  • possible duplicate of [Is there an easy way to compare two strings in a jsp?](http://stackoverflow.com/questions/1900843/is-there-an-easy-way-to-compare-two-strings-in-a-jsp) – Woot4Moo Jun 16 '11 at 18:12
  • please try to search before posting. – Woot4Moo Jun 16 '11 at 18:12

1 Answers1

2

The EL looks fine and should work fine. Rightclick the page in webbrowser and choose View Source. Do you see the checked attribute being set in the right place in the generated HTML?

But this is after all not the right attribute. On a HTML <option> element you need to set the selected attribute, not the checked attribute.

<c:if test="${gr.code == param.group}">selected</c:if>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555