【问题标题】:JSF: ExpressionLanguage if else expressionJSF:ExpressionLanguage if else 表达式
【发布时间】:2014-03-01 17:08:59
【问题描述】:

我该怎么做?我想显示来自实体的值,而不是字符串,但是如何将其作为有效代码执行?

itemLabel="#{mandatoryFriendship.receiver == loginBean.currentMandatory ? mandatoryFriendship.sender.surname  : mandatoryFriendship.receiver.surname mandatoryFriendship.receiver.name}"

感谢您的帮助

【问题讨论】:

  • 您的问题不清楚,要显示实体的值仅使用 #{entity.property} ,假设您的 entity 在 JSF beans 的范围内
  • EL 三元运算符工作正常。在 else 部分尝试不使用字符串连接的表达式。见working example
  • 不,我不想显示字符串,我想显示 bean 的属性。像这样 codeitemLabel="#{mandatoryFriendship.receiver == loginBean.currentMandatory} ? #{mandatoryFriendship.sender.surname} : #{mandatoryFriendship.receiver.surname} #{mandatoryFriendship.receiver.name}"code
  • 问题不在于#{entity.property}!问题是在一个条件下有两个 #{entity.property}

标签: jsf if-statement expression


【解决方案1】:

假设至少 EL 2.2 并且名称是非空字符串,您可以使用以下形式的表达式:

#{condition ? str0 : str1.concat(str2)}

对于旧版本(或空字符串),您可以使用:

#{condition ? str0 : str1}#{condition ? str0 : str2}

【讨论】:

    猜你喜欢
    • 2012-10-26
    • 1970-01-01
    • 2019-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-01
    • 2012-02-18
    • 2012-08-20
    相关资源
    最近更新 更多