如何在 xHtml 的 IF-Else 语句中插入 HTML 代码?

meh*_*alp 2 java jsf if-statement primefaces

我的页面上有primefaces 数据表

我在我的专栏上显示了两个数字。

我是这样的:

 #{pushNotification.status==1? 'FINISHED' : 'STOP'}
 *// If the data == 1 show 'FINISHED' else show 'STOP'*
Run Code Online (Sandbox Code Playgroud)

但我想在 if 语句中运行 HTML 代码,而不仅仅是文本。

我试过这样;

 #{pushNotification.status==1? '<a>FINISHED</a>' : 'STOP'}
Run Code Online (Sandbox Code Playgroud)

给了我“ EL 表达式”错误;

javax.el.ELException: EL Expression Unbalanced: ... #{pushNotification.status==1? '' : 'STOP' '
at com.sun.faces.facelets.el.ELText.findVarLength(ELText.java:428)
at com.sun.faces.facelets.el.ELText.parse(ELText.java:373)
at com.sun.faces.facelets.el.ELText.parse(ELText.java:325)
at com.sun.faces.facelets.compiler.TextUnit.flushTextBuffer(TextUnit.java:139)
at com.sun.faces.facelets.compiler.TextUnit.addInstruction(TextUnit.java:127)
at com.sun.faces.facelets.compiler.TextUnit.startTag(TextUnit.java:197)
at com.sun.faces.facelets.compiler.CompilationManager.pushTag(CompilationManager.java:313)
at com.sun.faces.facelets.compiler.SAXCompiler$CompilationHandler.startElement(SAXCompiler.java:247)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
Run Code Online (Sandbox Code Playgroud)

小智 5

<ui:fragment rendered="#{pushNotification.status == 1}">FINISHED</ui:fragment>
<ui:fragment rendered="#{pushNotification.status != 1}">STOP</ui:fragment>
Run Code Online (Sandbox Code Playgroud)

还要在 html 标签中添加xmlns:ui="http://java.sun.com/jsf/facelets"