Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EL comparison with equalIgnoreCase

Tags:

java

jsp

jsf

el

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?

like image 772
Ketan Avatar asked May 18 '12 13:05

Ketan


1 Answers

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.

like image 123
BalusC Avatar answered Sep 28 '22 07:09

BalusC