根据Role在jsf中导入模板

时间:2016-06-19 16:28:14

标签: jsf jsf-2 facelets

通常我的jsf页面是这样的:

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

正如您所注意到的,我有一个template.xhtml,我在每个jsf页面上导入。下面是我的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>

现在我想修改我的template.xhtml。我将检查是否为role = Professor,我将调用特定模板(templateForProfessor.xhtml),如果是role = student,我将调用另一个模板(templateForStudent.xhtml)。我不知道在哪里放置if条件。很高兴,如果你能提供样品。

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>

0 个答案:

没有答案