How to add various javascripts on the page when using ui: composition

I use a page with ui: using composition on it like this

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.prime.com.tr/ui" 
    xmlns:f="http://java.sun.com/jsf/core">

    <h:head>

        <title></title>

    </h:head>

    <h:body>

        <ui:composition template="./WEB-INF/templates/layout.xhtml">

            <ui:define name="title">#{faqAddUpdate.actionState} FAQ</ui:define>
            <ui:define name="content">

                <h:form id="faqAddUpdateForm" style="border-color: #000000;width: 960px;position: absolute;left: 150px;" prependId="false">
                ....
                ....

                </h:form>

            </ui:define>

        </ui:composition>

    </h:body>
</html>

My layout.xhtml is as follows

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html">

    <h:head>

        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

        <script type="textext/javascript" src="ckeditor/ckeditor.js" >
            <ui:insert name="script"></ui:insert>
        </script>

        <title>
            <ui:insert name="title">Login</ui:insert> 
        </title>

    </h:head>
    <h:body>
        <div id="top">
            <ui:insert name="top">
                <ui:include src="header.xhtml" id="header"/>
            </ui:insert>
        </div>
        <div>
            <div id="content">
                <ui:insert name="content"></ui:insert>
            </div>
        </div>
        <div id="bottom" style="position: absolute;top: 675px;width: 100%" align="center">
            <ui:insert name="bottom">
                <ui:include src="footer.xhtml" id="footer"/>
            </ui:insert>
        </div>
    </h:body>
</html>

on my page i use something like this

<h:body>

    <ui:composition template="./WEB-INF/templates/layout.xhtml">
        <ui:define name="script"></ui:define>
        <ui:define name="title">#{faqAddUpdate.actionState} FAQ</ui:define>
        <ui:define name="content">
        ....
       </ui:define>

   </ui:composition>

This adds the javascript tag to the section of my main page. Now I want to ask if I want to add another .js file to my page. I will need to define another ui: insert name = "script" in my layout.xhtml page like this?

<script type="textext/javascript" src="js/1.js" >
        <ui:insert name="script"></ui:insert>
</script>

<script type="textext/javascript" src="js/2.js" >
        <ui:insert name="script"></ui:insert>
</script>

etc. Or is there some kind of trick that I define in the script tag in my layout.xhtml once, and then based on the src attribute, I paste it into my page with ui list:

thank

+5
source share
2 answers

, ui: inserts. javascript . , , API .

<h:outputScript library="javascript" name="1.js" target="head" />

WebContent/resources/javascript 1.js javascript.

+13
<h:head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title>
        <ui:insert name="title">Login</ui:insert> 
    </title>

    <ui:insert name="script"></ui:insert>

</h:head>

<h:body>
    <div id="top">
        <ui:insert name="top">
            <ui:include src="header.xhtml" id="header"/>
        </ui:insert>
    </div>
    <div>
        <div id="content">
            <ui:insert name="content"></ui:insert>
        </div>
    </div>
    <div id="bottom" style="position: absolute;top: 675px;width: 100%" align="center">
        <ui:insert name="bottom">
            <ui:include src="footer.xhtml" id="footer"/>
        </ui:insert>
    </div>
</h:body>

-

<h:body>
    <ui:composition template="./WEB-INF/templates/Review_Template.xhtml">

        <ui:define name="title">FAQ Review</ui:define>

        <ui:define name="script"><h:outputScript library="Javascripts" name="jquery-1.7.1.js"/> </ui:define>
        <ui:define name="script"><h:outputScript library="Javascripts" name="1.js"/> </ui:define>
        <ui:define name="content">
            <h:form id="FaqGridForm" prependId="false" >
                ....
            </h:form>

        </ui:define>
    </ui:composition>
</h:body>

, Javascripts, , :)

+1

All Articles