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

大憨熊 提交于 2020-01-21 01:08:28

问题


I am using JSF 1.2

I am trying to print text using <h:outputtext>

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

Now this variable contains text with html tags. <b>,<i> etc...

But that displays content as it is instead of actual bold or italic html output.

Is there any way we can make this <h:outputText> such that it gives html response?


回答1:


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.




回答2:


Just set it to not escape.

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



回答3:


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



来源:https://stackoverflow.com/questions/10517200/houtputtext-prints-html-as-is-instead-of-actual-html

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