【问题标题】:Conditionally change label on calendar primefaces [duplicate]有条件地更改日历primefaces上的标签[重复]
【发布时间】:2016-06-23 06:39:57
【问题描述】:

我需要在 Primefaces 日历上有条件地更改标签。我有以下代码

<p:calendar value="#{requestMBean.requestTO.startDate}"  id="startDate" 
label="#{requestMBean.requestTO.requestType eq 'SINGLEDAY'}?#{msg['wfmt.label.request.fromDate']}:#{msg['wfmt.label.request.visitingDate']}}"
pattern="dd.MM.yyyy"/>

当验证失败时,我希望只看到一个标签。但我得到 "请输入:true?fromDate:visitingDate" 。

如何有条件地只渲染一个标签?

【问题讨论】:

  • 您的 el 不正确。 #{requestMBean.requestTO.requestType eq 'SINGLEDAY'}?#{msg['wfmt.label.request.fromDate']}:#{msg['wfmt.label.request.visitingDate']}} 像#{健康)状况 ?真:假}
  • 我应该如何改变它?

标签: jsf primefaces


【解决方案1】:
#{requestMBean.requestTO.requestType eq 'SINGLEDAY'}?#{msg['wfmt.label.request.fromDate']}:#{msg['wfmt.label.request.visitingDate']}} is wrong.

如果您愿意,可以将其更改为 "#{condition ? true statement : false statement}",以提高代码可读性。

已编辑

#{requestMBean.requestTO.requestType eq 'SINGLEDAY' ? msg['wfmt.label.request.fromDate'] : msg['wfmt.label.request.visitingDate']}

【讨论】:

  • 如果正确,请接受我的回答。
  • #{requestMBean.requestTO.requestType eq 'SINGLEDAY'?#{msg['wfmt.label.request.fromDate']}:#{msg['wfmt.label.request.visitingDate'] }} 。如果我添加这个,我会看到 EL 解析器错误
  • 为什么要使用多个 # 这不是必需的。看我编辑的答案
猜你喜欢
  • 2011-07-22
  • 1970-01-01
  • 1970-01-01
  • 2019-06-09
  • 2012-04-16
  • 1970-01-01
  • 1970-01-01
  • 2015-08-30
  • 1970-01-01
相关资源
最近更新 更多