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

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


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


<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
新增了查询框后页面其他内容消失了剩下了输入部门名称"和输入部门地址为什么?, <div> <!-- 查询面板 --> <h:form id="filterForm"> <p:panel header="查询条件" styleClass="filter-panel"> <div class="filter-row"> <p:outputLabel for="nameSearch" value="部门名称:" styleClass="filter-label" /> <p:inputText id="nameSearch" value="#{departmentBean.nameSearch}" placeholder="输入部门名称" /> </div> <div class="filter-row"> <p:outputLabel for="addrSearch" value="部门地址:" styleClass="filter-label" /> <p:inputText id="addrSearch" value="#{departmentBean.addrSearch}" placeholder="输入部门地址" /> </div> <div class="action-buttons"> <p:commandButton value="查询" action="#{departmentBean.search()}" icon="pi pi-search" style="margin-right: 10px;" update="deptTable" /> <p:commandButton value="重置" action="#{departmentBean.reset()}" icon="pi pi-refresh" process="@this" update="filterForm deptTable" /> </div> </p:panel> </h:form> </div> <p:dataTable value="#{departmentBean.departments}" var="dept" styleClass="data-table" paginator="true" rows="5" paginatorPosition="bottom" rowsPerPageTemplate="5,10,20" paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"> <p:column headerText="ID" style="width: 10%;"> #{dept.id} </p:column> <p:column headerText="部门名称" style="width: 20%;"> #{dept.name} </p:column> <p:column headerText="地址" style="width: 30%;"> #{dept.addr} </p:column> <p:column headerText="创建时间" style="width: 20%;"> <h:outputText value="#{dept.createTime}"> <f:convertDateTime pattern="yyyy-MM-dd HH:mm" /> </h:outputText> </p:column> <p:column headerText="更新时间" style="width: 20%;"> <h:outputText value="#{dept.updateTime}"> <f:convertDateTime pattern="yyyy-MM-dd HH:mm" /> </h:outputText> </p:column> </p:dataTable> <!-- 显示查询结果统计 --> <p:outputPanel style="margin-top: 15px;"> <p:outputLabel value="查询结果: 共 #{departmentBean.filteredDepartments.size()} 条记录" /> </p:outputPanel> </ui:define>
07-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值