Ketan Bhavsar
Ketan Bhavsar

Reputation: 5396

EL comparison with equalIgnoreCase

How to check equalIgnoreCase in EL?

String a = "hello";
a.equalsIgnoreCase("hello");

Now on JSP page..

<h:panelGroup rendered="#{patientNotePrescriptionVar.prescriptionSchedule ==  patientNotePresBackingBean.sendPrescription}">
            ... Some code here ....
</h:panelGroup>

Is there any way to compate patientNotePresBackingBean.sendPrescription as equalIgnoreCase?

Upvotes: 10

Views: 29357

Answers (2)

BalusC
BalusC

Reputation: 1108632

If you're using EL 2.2 (part of Servlet 3.0) or JBoss EL, then you should be able to just invoke that method in EL.

<h:panelGroup rendered="#{patientNotePrescriptionVar.prescriptionSchedule.equalsIgnoreCase(patientNotePresBackingBean.sendPrescription)}">

If you're not on EL 2.2 yet, then your best bet is passing both strings through JSTL fn:toLowerCase() (or fn:toUpperCase()) and then comparing it.

<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
...
<h:panelGroup rendered="#{fn:toLowerCase(patientNotePrescriptionVar.prescriptionSchedule) == fn:toLowerCase(patientNotePresBackingBean.sendPrescription)}">

Better, however, would be to not make them case sensitive. If they represent some kind of constants, better make them enums or something.

Upvotes: 22

adarshr
adarshr

Reputation: 62573

You could convert both the operands to lowercase and then equate them.

In case of JSTL, I would do

fn:toLowerCase(patientNotePrescriptionVar.prescriptionSchedule) eq fn:toLowerCase(patientNotePresBackingBean.sendPrescription)

Just check if you can do something similar in JSF. I've been out of touch of JSF of late, sorry.

Upvotes: 5

Related Questions