如何使用h:outputText输出HTML标签

本文介绍JSF中h:outputText组件的escape属性作用,该属性决定是否将HTML特殊字符转义。默认情况下,特殊字符会被转换为对应的HTML实体,通过设置escape属性为false可以输出原始的HTML内容。

h:outputText有一个  escape 属性用来处理html 标签. 默认值为true.这意味着所有特殊的符合都被转义为'&'代码. 请看下面示例:
 <h:outputText value="<b>This is a text</b>"/>

打印的结果是:

<b>This is a text</b>

而 <h:outputText escape="false" value="<b>This is a text</b>"/>

打印的结果是:

This is a text


<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:cc="http://java.sun.com/jsf/composite" xmlns:lkmcc="http://java.sun.com/jsf/composite/lkmComponent" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui" xmlns:c="http://java.sun.com/jsp/jstl/core"> <cc:interface/> <cc:implementation> <p:dialog header="周达成率记录" id="weekSummaryLogDia" widgetVar="weekSummaryLogDia" position="center" modal="true"> <p:dataTable id="summaryLog" widgetVar="summaryLog" value="#{wtWeekSummaryBean.showWeekSummaryLogs}" var="entity" currentPageReportTemplate="{startRecord}-{endRecord} of {totalRecords} records" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" emptyMessage="没有数据" rows="10" resizableColumns="true" style="width:450px;" rowHover="true" rowIndexVar="rowvar"> <p:column headerText="序号" style="width:15px;text-align: center;"> <h:outputText value="#{rowvar+1}"/> </p:column> <p:column headerText="周id" style="width:60px;text-align:center;"> <h:outputText value="#{entity.weekId}"/> </p:column> <p:column headerText="工号" sortBy="#{empNo}" style="width:60px;text-align:center;"> <h:outputText value="#{entity.empNo}"/> </p:column> <p:column headerText="姓名" width="50" style="text-align:center;"> <h:outputText value="#{entity.empName}"/> </p:column> <p:column headerText="网页工时" style="width:60px;text-align:right"> <h:outputText value="#{entity.webWt}"> <f:convertNumber maxFractionDigits="2" minFractionDigits="2"/> </h:outputText> </p:column> <p:column headerText="OPT工时" style="width:60px;text-align:right"> <h:outputText value="#{entity.optWt}"> <f:convertNumber maxFractionDigits="2" minFractionDigits="2"/> </h:outputText> </p:column> <p:column headerText="品质扣分" style="width:60px;text-align:right"> <h:outputText value="#{entity.deductWt}"> <f:convertNumber maxFractionDigits="2" minFractionDigits="2"/> </h:outputText> </p:column> <p:column headerText="合计产出" style="width:60px;text-align:right"> <h:outputLabel value="#{entity.totalWt}"> <f:convertNumber maxFractionDigits="2" minFractionDigits="2"/> </h:outputLabel> </p:column> <p:column headerText="实际出勤" style="width:60px;text-align:right"> <h:outputText value="#{entity.onDutyHour}"/> </p:column> <p:column headerText="出勤率" sortBy="#{onDutyRate}" style="width:50px;text-align:right"> <h:outputText value="#{entity.onDutyRate}"> <f:convertNumber type="percent" maxFractionDigits="1"/> </h:outputText> </p:column> <p:column headerText="达标率" sortBy="#{uptoStandareRate}" style="width:50px;text-align:right"> <h:outputText value="#{entity.uptoStandardRate}"> <f:convertNumber type="percent" maxFractionDigits="2" /> </h:outputText> </p:column> <p:column headerText="创建时间" style="display:none;"> <h:outputText value="#{entity.createTime}"> <f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss" timeZone="GMT+8"/> </h:outputText> </p:column> <p:column headerText="更新时间" style="display:none;"> <h:outputText value="#{entity.updateTime}"> <f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss" timeZone="GMT+8"/> </h:outputText> </p:column> </p:dataTable> </p:dialog> </cc:implementation> </html> 我新写的jsf碎片 别的项目要引用 这样写有没有问题
08-08
我想在弹框描述信息里放字段nameNo, <p:dialog header="明细" widgetVar="zhuanXuDetail" id="zhuanXuDetail" modal="true" resizable="true" width="950px" height="auto" contentHeight="flex" closeOnEscape="true" styleClass="detail-style" > <!-- 数据表格优化 --> <p:dataTable id="dataTableId2" value="#{zhuanXuReportBean.lazyEventDataDetailList}" lazy="true" paginator="true" rows="10" paginatorPosition="bottom" var="zhuanXuBean" emptyMessage="没有找到相关记录" styleClass="data-table fixed-layout-table" scrollable="true" scrollHeight="flex" scrollWidth="100%" tableStyle="table-layout: fixed; width: 100%" rowIndexVar="rowIndex" rowsPerPageTemplate="10,20,30" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" > <!-- 列宽优化 - 使用百分比宽度 --> <p:column headerText="厂房" style="text-align:center; width:8px;"> <h:outputText value="#{zhuanXuBean.factoryName}" styleClass="ellipsis-text"/> </p:column> <p:column headerText="单号" style="text-align:center; width:25px;" > <h:outputText value="#{zhuanXuBean.orderNo}" styleClass="ellipsis-text"/> </p:column> <p:column headerText="板件" style="text-align:center; width:3px;"> <h:outputText value="#{zhuanXuBean.plateNo}"> </h:outputText> </p:column> <p:column headerText="下机时间" style="text-align:center; width:40px;"> <h:outputText value="#{zhuanXuBean.confirmTime}"> <f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss" timeZone="GMT+8"/> </h:outputText> </p:column> <p:column headerText="转序时间" style="text-align:center; width:40px;"> <h:outputText value="#{zhuanXuBean.transferTime}"> <f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss" timeZone="GMT+8"/> </h:outputText> </p:column> <p:column headerText="状态" style="text-align:center; width:3px;"> <h:outputText value="#{zhuanXuBean.status}"> </h:outputText> </p:column> <p:column headerText="等待转序" style="text-align:center; width:30px;"> <h:outputText value="#{zhuanXuBean.transferDurationMinutes}" styleClass="ellipsis-text"/> </p:column> </p:dataTable> </p:dialog>
最新发布
08-22
<p:dataTable id="nonStdPart_dt" widgetVar="nonStdPart_dt" value="#{nonStdPartBean.nonStdParts}" var="item" paginator="true" paginatorPosition="bottom" rows="20" rowsPerPageTemplate="10,20,30,40,50" currentPageReportTemplate="(总记录: {totalRecords}, 页: {currentPage}/{totalPages})" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" emptyMessage="没有数据" resizableColumns="true" rowHover="true" rowIndexVar="rowvar" lazy="true" > <p:column headerText="操作" style="width:#{nonStdPartBean.isRelatedRole('工程部角色','工程管理角色') ? '150px;': nonStdPartBean.isRelatedRole('接单')? '100px;' : '50px;'}" rendered="#{nonStdPartBean.isRelatedRole('工程部角色','工程管理角色','接单','零件计划角色')}" > <p:outputPanel style="width:fit-content;display:flex;justify-content: center;gap:10px;padding: 0 5px;"> <!-- 零件工程 --> <p:commandLink value="上传图档" actionListener="#{nonStdPartBean.stagingKey4Down(item)}" disabled="#{not empty item.getMore('engUploadOperator')}" rendered="#{nonStdPartBean.isRelatedRole('工程部角色','工程管理角色') and item.state eq NonStdPartState.待工程跟进}" /> <p:commandLink value="公差待预" actionListener="#{nonStdPartBean.stagingKey4Tolerance(item)}" update="@(.toleranceDialogSc)" rendered="#{nonStdPartBean.isRelatedRole('工程部角色','工程管理角色') and item.state eq NonStdPartState.待工程跟进}" /> <p:commandLink value="完成" actionListener="#{nonStdPartBean.changeState(item)}" rendered="#{nonStdPartBean.isRelatedRole('工程部角色','工程管理角色') and item.state eq NonStdPartState.待工程跟进}" /> <!-- 接单 --> <p:commandLink value="下载图档" ajax="false" onclick="PrimeFaces.monitorDownload(start, stop);" update="" style="margin-right: 5px;" disabled="#{empty item.getMore('engUploadOperator')}" rendered="#{nonStdPartBean.isRelatedRole('接单') and item.state eq NonStdPartState.待接单跟进}" > <p:fileDownload value="#{nonStdPartBean.getDownImgFile(item.boardKey)}" /> </p:commandLink> <!-- 接单, 零件计划 --> <p:commandLink id="doneCL" value="完成" actionListener="#{nonStdPartBean.removeBoard(item.boardKey)}" rendered="#{(nonStdPartBean.isRelatedRole('接单') and item.state eq NonStdPartState.待接单跟进) or (nonStdPartBean.isRelatedRole('零件计划角色') and item.state eq NonStdPartState.待计划跟进)}" /> </p:outputPanel> </p:column> <p:column headerText="单号" style="text-align:center; width: 110px; "> <h:outputText value="#{item.orderNo}"/> </p:column> <p:column headerText="零件编号" style="text-align:left; width: 130px;"> <h:outputText value="#{item.partCode}"/> </p:column> <p:column headerText="零件说明" style="text-align:start; width:130px;"> <h:outputText value="#{item.partDesc}"/> </p:column> <p:column headerText="备注" style="text-align:start; min-width: 250px"> <h:outputText id="remarkText" value="#{nonStdPartBean.concatMemoAndToleranceText(item)}"/> <p:tooltip id="toleranceTextTooltip" for="remarkText" value="#{nonStdPartBean.concatMemoAndToleranceText(item)}" position="top" /> </p:column> <p:column headerText="数量" style="text-align:center; width: 50px;"> <h:outputText value="#{item.qty}"/> </p:column> <p:column headerText="来源类型" style="text-align:center; width: 70px;"> <h:outputText value="#{item.sourceType}"/> </p:column> <p:column headerText="状态" style="text-align:center; width: 90px;"> <h:outputText value="#{item.state}"/> </p:column> <p:column headerText="下单日期" style="text-align:center; width:100px;" sortBy="#{sort1}"> <h:outputText value="#{item.bookDate}"> <f:convertDateTime pattern="dd/MM HH:mm" timeZone="GMT+8"/> </h:outputText> </p:column> <p:column headerText="工程完成日期" style="text-align:center; width:100px;"> <h:outputText value="#{nonStdPartBean.parseDate(item.getMore('engDoneDate'))}"> <f:convertDateTime pattern="dd/MM HH:mm" timeZone="GMT+8"/> </h:outputText> </p:column> <p:column headerText="创建日期" style="text-align:center; width:100px;"> <h:outputText value="#{item.creationDate}"> <f:convertDateTime pattern="dd/MM HH:mm" timeZone="GMT+8"/> </h:outputText> </p:column> </p:dataTable> 备注栏看不到是什么原因
07-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值