Javascript does not work under JSF template

前端 未结 2 918
你的背包
你的背包 2021-02-10 00:41

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 load

相关标签:
2条回答
  • 2021-02-10 01:22

    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...

    0 讨论(0)
  • 2021-02-10 01:28

    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:

    • How to include another XHTML in XHTML using JSF 2.0 Facelets?
    0 讨论(0)
提交回复
热议问题