在 JSF EL 表达式中连接两个字符串

2022-09-01 01:42:21

我有以下 el 表达式:

<af:outputText value="#{viewArticle.publish ? ('Publish on ' + viewArticle.publishDate + ' by ' + viewArticle.publishFirstName + ' ' + viewArticle.publishLastName) : 'Draft version'}"/>

但我得到了

java.lang.NumberFormatException: For input string: "Publish on "

如何加入字符串?


答案 1

您可以使用 String.concat 函数:

<af:outputText value="#{viewArticle.publish ? 'Publish on '.concat(viewArticle.publishDate).concat(' by ').concat(viewArticle.publishFirstName).concat(' ').concat(viewArticle.publishLastName) : 'Draft version'}"/>


答案 2

你应该写

value  = "#{someBean.aProperty}  something you want in between #{someBean.anotherProperty}"