gpt4 book ai didi

java - JSF 字符比较未按预期工作

转载 作者:行者123 更新时间:2023-12-01 14:44:59 26 4
gpt4 key购买 nike

我有一个 JSF 页面,我根据托管 bean 属性控制渲染器属性。

<p:commandLink action="#{smartphoneBean.drillDown(smartphone.ldapuser,smartphone.productGrp)}"
rendered="#{!(smartphone.ldapuser.charAt(0) ge '0' and smartphone.ldapuser.charAt(0) le '9')}" value="#{smartphone.ldapuser}">

一旦我运行我的代码。仍会呈现此值以任意数字开头的 commandLink。

我希望比较 char 值的整数表示形式。

你对这个问题有什么想法吗?

最佳答案

String#charAt(int)返回一个 char (Unicode 代码点),在 EL 中解释为 Number'0' 被计算为 String,而不是 Number。因此比较总是会产生不想要的结果。

字符 09 的 Unicode 代码点为 48 to 57 。所以,应该这样做:

rendered="#{!(smartphone.ldapuser.charAt(0) ge 48 and smartphone.ldapuser.charAt(0) le 57)}"  value="#{smartphone.ldapuser}">

另请参阅:

关于java - JSF 字符比较未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15520637/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com