在JSF中呈现模板而不是页面

时间:2015-09-16 12:25:33

标签: jsf-2

当我运行以下代码时,会呈现template.xhtml而不是searchBooks.xhtml。 web.xml的欢迎文件为searchBooks.xhtml。所以我希望在点击项目根网址时呈现searchBooks.xhtml。但是,会呈现内容为template.xhtml的页面。如果我访问它project_context/searchBooks.xhtml,则相同。我错过了什么?

JSF模板 - template.xhtml

<!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://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html">
<head>
  <title><ui:insert name="title">Default title</ui:insert></title>
</head>

<body>
<ui:debug hotkey="x" rendered="#{initParam['javax.faces.FACELETS_DEVELOPMENT']}"/>

<div id="header">
    <ui:insert name="header">
        Header area.  See comments below this line in the source.
        <!--  include your header file or uncomment the include below and create header.xhtml in this directory -->
        <!-- <ui:include src="header.xhtml"/> -->
    </ui:insert>

</div>


<div id="content">

  <ui:insert name="content">
        Content area.  See comments below this line in the source.
        <!--  include your content file or uncomment the include below and create content.xhtml in this directory -->
        <!-- <div> -->
        <!-- <ui:include src="content.xhtml"/> -->  
        <!-- </div> -->
  </ui:insert>

</div>

<div id="footer">

  <ui:insert name="footer">
        Footer area.  See comments below this line in the source.
        <!--  include your header file or uncomment the include below and create footer.xhtml in this directory -->
        <!--<ui:include src="footer.xhtml"/>  -->
  </ui:insert>
</div>

</body>

</html>

JSF代码 - searchBooks.xhtml

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

<h:head>
<title></title>
</h:head>
<h:body>
<ui:composition template="templates/template.xhtml"></ui:composition>

<ui:define name="header"> Custom Header</ui:define>
<ui:define name="content">

<h:form>
Author : <h:inputText value ="#{book.author}"></h:inputText><br/>
ISBN No. : <h:inputText value ="#{book.isbnNo}"></h:inputText><br/>
Book Name : <h:inputText value ="#{book.name}"></h:inputText><br/>
Price : <h:inputText value ="#{book.price}"></h:inputText><br/>
Is on Sale ? : <h:selectBooleanCheckbox value = "#{book.onSale}"></h:selectBooleanCheckbox>
Categories : <h:selectManyCheckbox value ="#{book.categories}">
<f:selectItem itemLabel ="Fiction" itemValue = "F"></f:selectItem>
<f:selectItem itemLabel ="Non-Fiction" itemValue = "NF"></f:selectItem>
<f:selectItem itemLabel ="Romance" itemValue = "R"></f:selectItem>
</h:selectManyCheckbox>
<h:commandButton value="Search" action = "#{bookSearch.searchBooks}" ></h:commandButton>
</h:form>
Search Results:
 <h:outputText rendered ="#{book.author ne null}" value ="#{book.author}"></h:outputText><br/>
 <h:outputText rendered ="#{book.isbnNo ne null}" value = "#{book.isbnNo}"></h:outputText><br/>
 <h:outputText rendered ="#{book.name ne null}" value ="#{book.name}"></h:outputText><br/>
 <h:outputText rendered ="#{book.price gt  0}" value ="#{book.price}"></h:outputText><br/>
 <h:outputText rendered ="#{book.onSale}" value = "#{book.onSale}"></h:outputText>

Categories : 

   <h:dataTable value="#{book.categories}" var="item">
    <h:column>#{item}</h:column>
   </h:dataTable>
   </ui:define>
   <ui:define name="footer">Custom footer</ui:define>
</h:body>
</html>

0 个答案:

没有答案