Comparing strings in EL [duplicate]
Asked Answered
J

1

11

I'm giving a User object to JSP and want to compare an attribute of the user with a given String. What I'm doing right now is the following:

<input type="radio" name="lang" value="ger" <c:if test="${user.comLanguage.equals("ger")}">checked="yes"</c:if>/>German</br>

But all I get is the following Exception:

org.apache.jasper.JasperException: /WEB-INF/jsp/library/home.jsp (line: 22, column: 95) equal symbol expected

where column 95 is one of the letters of comLanguage.

What's the correct syntax here?

Journey answered 2/12, 2011 at 11:30 Comment(1)
Your initial syntax will by the way work if you're using EL 2.2. and use singlequotes instead of doublequotes inside the method call.Agathaagathe
M
21

Try this :

<c:if test="${user.comLanguage=='ger'}">

Also you can try ternary if:

${user.comLanguage=='ger' ? 'checked' : ''}
Merrilee answered 2/12, 2011 at 11:34 Comment(2)
+1. Or, instead of ==, the eq keyword does the same thingShane
Seems like EL uses Java objects but not all its methods. Thank you.Parnassus

© 2022 - 2024 — McMap. All rights reserved.