Normally I have my jsf page like this:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
template="/WEB-INF/jsf/template.xhtml">
<ui:define name="content">
<!-- Content Header -->
<section class="content-header">
</section>
<!-- Main content -->
<section class="content">
<h:form>
<div>
<div>
<div>
<div>
<div >
<h:outputText value="Hello World!"/>
</div>
</div>
</div>
</div>
</div>
</h:form>
</section>
</ui:define>
As you noticed, I have a template.xhtml which I import on each jsf page. Below is my template.xhtml.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui">
<f:view>
<h:head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="-1"/>
<h:outputScript library="primefaces" name="jquery/jquery.js" />
<link type="text/css" rel="stylesheet" href="#{request.contextPath}/css/jsfdefault.css" />
</h:head>
<h:body>
<div class="outer-container">
<div class="inner-container">
<div class="main" style="min-height: 500px">
<div style="width:100%;border: none;">
<ui:include src="/jsf/menu.xhtml"></ui:include>
</div>
<div class="content" style="width: 100%; margin-top:-8px;">
<ui:insert name="content">
</ui:insert>
</div>
<div class="clearer"></div>
</div>
</div>
</div>
</h:body>
</f:view>
</html>
Now I want to modify my template.xhtml. I will check if role = Professor, I will call specific template (templateForProfessor.xhtml) and if role = student, I will call another template (templateForStudent.xhtml). I am not sure where to place the if condition. Glad if you can provide a sample.
templateForProfessor.xhtml
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui">
<f:view>
<h:head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="-1"/>
<h:outputScript library="primefaces" name="jquery/jquery.js" />
<link type="text/css" rel="stylesheet" href="# {request.contextPath}/css/jsfdefault.css" />
</h:head>
<h:body>
<div class="outer-container">
<div class="inner-container">
<div class="main" style="min-height: 500px">
<div style="width:100%;border: none;">
<ui:include src="/jsf/menu.xhtml"></ui:include>
</div>
<div class="content" style="width: 100%; margin-top:-8px;">
<ui:insert name="content">
</ui:insert>
</div>
<div class="clearer"></div>
</div>
</div>
</div>
</h:body>
</f:view>
</html>
templateForStudent.xhtml
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui">
<f:view contentType="text/html">
<h:head>
<link type="text/css" rel="stylesheet"
href="#{request.contextPath}/css/default.css" />
</h:head>
<h:body>
<p:layout fullPage="true">
<p:layoutUnit id="top" position="north" >
<div>
<h:form>
<div>
<div style="float: right;">
</div>
</div>
</h:form>
</div>
</p:layoutUnit>
<p:layoutUnit id="bottom" position="south" >
</p:layoutUnit>
<p:layoutUnit id="left" position="west">
<ui:insert name="leftContent">
</ui:insert>
</p:layoutUnit>
<p:layoutUnit id="right" position="east">
<ui:insert name="rightContent">
</ui:insert>
</p:layoutUnit>
<p:layoutUnit id="center" position="center" size="0">
</p:layoutUnit>
</p:layout>
</h:body>
</f:view>
</html>