与equalIgnoreCase进行EL比较

Ket*_*tan 8 java jsf jsp el

如何检查EL中的equalIgnoreCase?

String a = "hello";
a.equalsIgnoreCase("hello");
Run Code Online (Sandbox Code Playgroud)

现在在JSP页面上..

<h:panelGroup rendered="#{patientNotePrescriptionVar.prescriptionSchedule ==  patientNotePresBackingBean.sendPrescription}">
            ... Some code here ....
</h:panelGroup>
Run Code Online (Sandbox Code Playgroud)

有没有办法比较patientNotePresBackingBean.sendPrescriptionequalIgnoreCase?

Bal*_*usC 20

如果您使用的是EL 2.2(Servlet 3.0的一部分)或JBoss EL,那么您应该能够在EL中调用该方法.

<h:panelGroup rendered="#{patientNotePrescriptionVar.prescriptionSchedule.equalsIgnoreCase(patientNotePresBackingBean.sendPrescription)}">
Run Code Online (Sandbox Code Playgroud)

如果你还没有使用EL 2.2,那么你最好的选择是将两个字符串传递给JSTL fn: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)}">
Run Code Online (Sandbox Code Playgroud)

然而,更好的做法是不要让它们区分大小写.如果它们代表某种常量,最好使它们成为枚举或其他东西.

  • 不,它以`fn:`开头,而不是`c:`. (3认同)

ada*_*shr 5

您可以将两个操作数都转换为小写,然后将它们等同起来。

在 JSTL 的情况下,我会做

fn:toLowerCase(patientNotePrescriptionVar.prescriptionSchedule) eq fn:toLowerCase(patientNotePresBackingBean.sendPrescription)
Run Code Online (Sandbox Code Playgroud)

只需检查您是否可以在 JSF 中做类似的事情。抱歉,我最近与 JSF 脱节了。