Javascript Does Not Work Under JSF Template
I'm using JSF templates and Primefaces. Javascript code does not seem to be working under ui:composition and ui:define tags. The following code is not hitting the loaded() method.
Solution 1:
Everything outside <ui:composition>
is ignored during building the view. Also, redeclaring <h:body>
once again is unnecessary. To use a script which runs during on page load, better use a <h:outputScript target="body">
. This will be relocated to end of body and thus be invoked after the necessary HTML DOM elements are been built. This is also somewhat faster than an onload
.
All with all, your entire content.xhtml
must look like this:
<ui:composition template="/template/template.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<ui:define name="content">
<h:outputScript target="body">
alert("Working!!");
</h:outputScript>
<p class="item">Random text</p>
</ui:define>
</ui:composition>
See also:
Solution 2:
You are passing "content" to the template. If your template does not include "content", it won't be including in the resulting HTML.
Post the template.xhtml and let's see...
Post a Comment for "Javascript Does Not Work Under JSF Template"