Skip to content Skip to sidebar Skip to footer

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 entirecontent.xhtml must look like this:

<ui:compositiontemplate="/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:definename="content"><h:outputScripttarget="body">
            alert("Working!!");
        </h:outputScript><pclass="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"