【问题标题】:How to insert HTML code in IF-Else statement in xHtml?如何在 xHtml 的 IF-Else 语句中插入 HTML 代码?
【发布时间】:2014-06-04 12:16:14
【问题描述】:

我的页面上有 primefaces 数据表。

我在列上显示两个数字。

我确实喜欢这样:

 #{pushNotification.status==1? 'FINISHED' : 'STOP'}
 *// If the data == 1 show 'FINISHED' else show 'STOP'*

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

我试过这样;

 #{pushNotification.status==1? '<a>FINISHED</a>' : 'STOP'}

给了我“EL Expression”错误;

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)

【问题讨论】:

  • 这不是你的 el 表达问题。你可以试试这个:#{pushNotification.status=='1' 吗? “完成”:“停止”}
  • 我知道它的工作原理。但我想在 if 或 else 语句中运行 html 代码。

标签: java jsf if-statement primefaces


【解决方案1】:
<ui:fragment rendered="#{pushNotification.status == 1}">FINISHED</ui:fragment>
<ui:fragment rendered="#{pushNotification.status != 1}">STOP</ui:fragment>

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

【讨论】:

    猜你喜欢
    • 2017-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-31
    • 2019-09-17
    • 2015-07-07
    相关资源
    最近更新 更多