gpt4 book ai didi

jsf - 如何将内容呈现为纯文本和 URL 编码

转载 作者:行者123 更新时间:2023-12-04 07:49:02 24 4
gpt4 key购买 nike

JSF 2.x/Primefaces 7.x
假设我有一个

<p:outputLabel id="myLabel">
Here some static text written from a colleage without java background,
but mixed with #{myBean.name} information from java object
<p:outputLabel>
<h:outputLabel> .
我想在同一页面上提供电子邮件链接 <a href="mailto:">并将标签字段 (id=myLabel) 中的内容放入电子邮件中。
我还发现了这样的例子 <a href="mailto:?subject=mySubject&body=myBody">预先填写电子邮件。所以 myBody 应该是来自 id=myLabel 字段的内容。
我正在寻找一种解决方案,将渲染的内容从标签中提取为正文。
我假设,内容也必须是 url 编码的。
任何提示?
提前致谢。

最佳答案

您可以做的是添加 p:outputLabel 的内容到一个变量,使用 c:var .例如:

<c:set var="myVar">Some text at #{now}</c:set>
<p:outputLabel>#{myVar}</p:outputLabel>
这允许您重复使用 myVar在一个链接中。在您的情况下,您想将其用作 URL 参数。所以它确实需要进行 URL 编码。为此,您只需使用 h:outputLinkf:param s,它将自动进行 URL 编码:
<h:outputLink value="mailto:">
<f:param name="subject" value="#{myVar}" />
<f:param name="body" value="#{myOtherVar}" />
Send mail
</h:outputLink>
您也可以创建 a custom EL function这样做,或者,如果您使用的是 OmniFaces,您可以使用 of:encodeURL :
<c:set var="myVar">Some text at #{now}</c:set>
<p:outputLabel>#{myVar}</p:outputLabel>
'myVar' URL encoded: #{of:encodeURL(myVar)}

关于jsf - 如何将内容呈现为纯文本和 URL 编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67074728/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com