<h:outputtext> prints HTML as-is instead of actual HTML [duplicate]

a 夏天 提交于 2019-11-30 08:19:50

You should set in the h:outputText tag:

escape="false"

But remember that mixing "view" construction (i.e., creating a string with HTML tags) between the JSF view page and the underlying bean is kinda bad practice. All the "view production" should be in the view page.

Just set it to not escape.

<h:outputText id="warningDose" escape="false" styleClass="redText" value="#{templatePrescriptionMaintenanceBackingBean.doseWarningText}"></h:outputText>
goyalshub1509

I had a very similar problem. My question is here

My xhtml page looks like -

<h:outputText  itemEscaped="false" escape="false"    value="#{singleViewResultDO.associatedCode}" />

associatedCode is getting value from a SQL query where I want to use HTML tag to have conditional styling.

Here is my SQL query looks like:

Select A, REPLACE(Wm_Concat(DISTINCT  CASE WHEN sv.rmvd = 0 THEN  ' '||sv.CMPNION_CD  ELSE '<span style=\"color:red; \">' || ' '||sv.CMPNION_CD|| '</span>' END),' , ','') ,  "
from Table

Ignore REPLACE and WM_CONCAT as it is for displaying comma separated values. The piece of code relevant is

CASE WHEN sv.rmvd = 0 THEN  ' '||sv.CMPNION_CD  ELSE '<span style=\"color:red; \">' || ' '||sv.CMPNION_CD|| '</span>' END

I want to have tag based on a condition rmvd = 0.. Since, I have escape="false" in my , I don't need to escape my html tags in query. What I mean is no need to convert < to < > to > and " to "

Also note that since I have double quotes "" in my span, I need to escape it once so it won't be escaped when it reaches .

I am getting my output as desired - 8000778 in red color

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!