您不能仅仅通过JSFajax更新来更新标题,因为
<title>它不是JSF组件。您也不能将HTML或JSF组件放入中
<title>,这是非法的
HTML语法。
最好的选择是使用Javascript而不是通过将标题分配给来更新标题
document.title。您可以使用
RequestContext#execute()它。
String fullName = current.getFirstName() + " " + current.getSurName();context.execute("document.title='" + fullName + "'");由于这似乎是用户控制的数据,因此我将对其
StringEscapeUtils#escapeJavascript()进行转义以防止潜在的XSS攻击漏洞。
String fullName = current.getFirstName() + " " + current.getSurName();context.execute("document.title='" + StringEscapeUtils.escapeJavascript(fullName) + "'");另一种方法是使用OmniFaces
<o:onloadscript>。
<o:onloadscript>document.title='#{of:escapeJS(viewBacking.current.firstName)} #{of:escapeJS(viewBacking.current.surName)}'</o:onloadscript>这将在每个ajax请求上重新执行。



