Muhammad Yawar
Muhammad Yawar

Reputation: 434

Bootstrap not working under ui composition tag JSF

I am designing a website, in which i want to include my Navbar in all pages, the problem is that whenever I write navbar code inside ui:composition tag than bootstrap goes off. without this tag everything is working fine.

the Working code

    <?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"
    xmlns:f="http://java.sun.com/jsf/core" xml:lang="en" lang="en">
<h:head>


    <title>JSF 2.x Page</title>
    <meta http-equiv="keywords" content="enter,your,keywords,here" />
    <meta http-equiv="description"
        content="A short description of this page." />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />

    <h:outputStylesheet library="css" name="black.css"  />
    <h:outputStylesheet library="css" name="bootstrap.css"  />

    <h:outputScript library="js" name="bootstrap.js" />
    <h:outputScript library="js" name="bootstrap.min.js" />

</h:head>
<h:body>

        <nav class="navbar navbar-inverse">
        <div class="container-fluid">
            <div class="navbar-header">
                <a class="navbar-brand" href="#">My Task</a>
            </div>

            <button class="btn btn-success navbar-btn">Projects</button>
            <button class="btn btn-success navbar-btn">Objects</button>
            <button class="btn btn-success navbar-btn">Properties</button>
            <button class="btn btn-success navbar-btn">Property Types</button>

        </div>
        </nav>

</h:body>
</html>

But with the ui:composition, bootstrap is not working

    <?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"
    xmlns:f="http://java.sun.com/jsf/core" xml:lang="en" lang="en">
<h:head>
    <title>JSF 2.x Page</title>
    <meta http-equiv="keywords" content="enter,your,keywords,here" />
    <meta http-equiv="description"
        content="A short description of this page." />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />

    <h:outputStylesheet library="css" name="black.css"  />
    <h:outputStylesheet library="css" name="bootstrap.css"  />

    <h:outputScript library="js" name="bootstrap.js" />
    <h:outputScript library="js" name="bootstrap.min.js" />

</h:head>
<h:body>
<ui:composition>
        <nav class="navbar navbar-inverse">
        <div class="container-fluid">
            <div class="navbar-header">
                <a class="navbar-brand" href="#">My Task</a>
            </div>

            <button class="btn btn-success navbar-btn">Projects</button>
            <button class="btn btn-success navbar-btn">Objects</button>
            <button class="btn btn-success navbar-btn">Properties</button>
            <button class="btn btn-success navbar-btn">Property Types</button>

        </div>
        </nav>
</ui:composition>

</h:body>
</html>

Upvotes: 0

Views: 887

Answers (1)

Mike Balthasar
Mike Balthasar

Reputation: 183

The ui:composition Tag is used to reference a template via its 'template' attribute like:

<ui:composition template="template.xhtml"> 

The template is just a regular faces file that contains one or more <ui:insert> tags with a name attribute that you can reference from the file using the template using the <ui:define> tag. For example if your template contains:

<ui:insert name="top">

than you can reference it from another file within the <ui:composition> tag like:

<ui:define name="top">

The resulting html will be the one created from the template only the <ui:define> parts are replaced by whatever html is generated in your <ui:insert> tag... So, without the template you are not creating proper html, no head no body..

Upvotes: 1

Related Questions