【问题标题】:Primefaces rendered if list contains a value如果列表包含值,则呈现 Primefaces
【发布时间】:2014-05-03 02:36:08
【问题描述】:
<h:outputText rendered="#{bean.list.contains(watever)}" value="show this "/>

如果列表包含特定值,我想使用渲染来显示一些文本,但是我在 eclipse 中得到一个语法错误说明

方法必须有签名“boolean method(), boolean method(String), boolean method(String, String), 布尔方法(字符串,字符串,字符串),布尔方法(字符串,字符串,字符串,字符串),布尔方法(字符串, 字符串,字符串,字符串,字符串),布尔方法(字符串,字符串,字符串,字符串,字符串,字符串),布尔值 方法(字符串,字符串,字符串,字符串,字符串,字符串,字符串),...................... 但有签名“布尔方法(对象)”

这样做的正确方法是什么?

【问题讨论】:

  • 在你的 bean 中尝试一个自定义方法,和containsmethod 做同样的事情

标签: java primefaces xhtml


【解决方案1】:

你试过了吗

<h:outputText rendered="#{bean.list.contains('watever')}" value="show this "/>

而不是?

<h:outputText rendered="#{bean.list.contains(watever)}" value="show this "/>

【讨论】:

  • 是的,我已经尝试过它不起作用,但评论中的解决方法有效。问题是它自己的包含方法需要一个对象,所以我不得不创建一个类似的方法来代替字符串
  • 要使contains() 方法起作用,您需要覆盖Object 的equals()hashCode() 方法。
猜你喜欢
  • 2018-08-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-12
  • 2020-07-19
  • 2021-12-16
  • 1970-01-01
  • 2021-09-01
相关资源
最近更新 更多