在一个previous question我问了一下更新菜单栏。 BalusC告诉我,我需要包含菜单栏添加的形式。
In a previous question I asked about updating a menu bar. BalusC told me that I need to add the form containing the menu bar.
我想延长这个问题要问,如果我可以更新标题文本。模板的存在,而我填写值使用
I would like to extend that question to ask if I can update the text in the title. A template is being used and I fill in the value using
<ui:define name="AreaTitle">
#{viewBacking.current.firstName} #{viewBacking.current.surName}
</ui:define>
该模板有
<h:head>
<title><ui:insert name="AreaTitle">Master template</ui:insert></title>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</h:head>
我觉得奇怪,在标题中定义所以没有被定义的形式。我把在viewBacking.current一个破发点这样我就可以看到它的时候使用它。就算我打刷新重新显示形式,它不会再次命中断点。只有当我去到不同的页面,不同的内容做它再次击中了破发点。在为刷新
It seems strange to define a form in the header so none is defined. I put a break point in the viewBacking.current so I can see when it uses it. Even if I hit the refresh to redisplay the form, it won't hit the break point again. Only when I go to a different page with different content does it hit the break point again. The for the refresh is
public void refreshForm() {
RequestContext context = RequestContext.getCurrentInstance();
context.update("menuForm:masterMenuBar");
context.update("AreaTitle");
}
这显示了BalusC给我的masterMenuBar的previous解决方案。这很可能是,我不能做什么,我要求做的,但我想确认,如果是这样的话。
This shows the previous solution which BalusC gave me on the masterMenuBar. It could well be that I can't do what I'm asking to do, but I'd like confirmation if that is the case.
谢谢, 宜兰
您不能更新由JSF AJAX更新的称号,只是因为&LT;冠军&GT;
不是JSF组件。你也可以不把HTML或JSF组件的&LT;冠军&GT;
,这是的非法 HTML语法。
You can't update the title by JSF ajax update simply because <title>
is not a JSF component. You also can't put HTML or JSF components in <title>
, this is illegal HTML syntax.
您最好的选择是使用JavaScript,而不是更新的标题将其分配给了 document.title时
。您可以使用的RequestContext#的execute()
这一点。
Your best bet is to use JavaScript instead to update the title by assigning it to the document.title
. You can use RequestContext#execute()
for this.
String fullName = current.getFirstName() + " " + current.getSurName();
context.execute("document.title='" + fullName + "'");
由于这似乎是用户控制数据,我会用 StringEscapeUtils#escapeJavaScript()
,以逃避它以prevent潜在的 XSS攻击漏洞的。
String fullName = current.getFirstName() + " " + current.getSurName();
context.execute("document.title='" + StringEscapeUtils.escapeJavaScript(fullName) + "'");
另一种方法是使用 OmniFaces 的 &LT;○:onloadScript&GT;
<o:onloadScript>document.title='#{of:escapeJS(viewBacking.current.firstName)} #{of:escapeJS(viewBacking.current.surName)}'</o:onloadScript>
这将在每一个Ajax请求重新执行。
This will be re-executed on every ajax request.