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
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.
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 + "'");
Since this seems to be user-controlled data, I would use StringEscapeUtils#escapeJavaScript() to escape it in order to prevent potential XSS attack holes.
String fullName = current.getFirstName() + " " + current.getSurName();
context.execute("document.title='" + StringEscapeUtils.escapeJavaScript(fullName) + "'");
An alternative is to use OmniFaces <o:onloadScript>.
<o:onloadScript>document.title='#{of:escapeJS(viewBacking.current.firstName)} #{of:escapeJS(viewBacking.current.surName)}'</o:onloadScript>
This will be re-executed on every ajax request.