2012-05-18 9 views
6

EL相比如何EL檢查equalIgnoreCase?與equalIgnoreCase

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

現在JSP頁面上..

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

有什麼辦法來compate patientNotePresBackingBean.sendPrescription爲equalIgnoreCase?

回答

17

如果你使用的EL 2.2(3.0的Servlet的一部分)或JBoss的EL,那麼你應該能夠只是調用該方法在EL。

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

如果你不是EL 2.2還沒有,那麼你最好的選擇是通過JSTLfn:toLowerCase()(或fn:toUpperCase())經過兩個字符串,然後比較它。

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

但是,最好不要使它們區分大小寫。如果它們代表某種常量,最好使它們成爲枚舉或其他東西。

+0

感謝BalusC,但在這種情況下,也adarshr的回答,即使它給像'屬性前綴FN不對應錯誤到任何導入的標籤庫' – Ketan

+0

您當然需要在JSP的頂部聲明'fn' taglib(完全像您爲JSF'h' taglib所做的那樣)。檢查文檔,瞭解確切的語法:http://docs.oracle.com/javaee/5/jstl/1.1/docs/tlddocs/fn/tld-summary.html – BalusC

+0

喔!我認爲它是'c'taglib的一部分... – Ketan

3

你可以轉換兩個操作數爲小寫,然後把它們等同起來。

在JSTL的情況下,我會做

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

只是檢查,如果你能做到在JSF類似的東西。最近我已經脫離JSF了,對不起。

+0

如果我沒看錯,你先回答完全不同的東西?否則我不會發布重複的答案。 – BalusC

+0

不,我只是回答了第一行,後來又添加了JSTL示例:)此外,你的並不是重複的。它補充了我的答案。 – adarshr

+0

它給了一個錯誤...... 屬性前綴** ** FN不對應任何進口標籤庫 – Ketan