【问题标题】:Need help about JSF and <ui:insert>, <ui:define>需要有关 JSF 和 <ui:insert>、<ui:define> 的帮助
【发布时间】:2014-11-19 07:42:44
【问题描述】:

我对这个简单的代码有问题,我无法正确查看“footer.xhtml”内容(单词“Wooorks”)

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>piloto_18</display-name>
  <welcome-file-list>
    <welcome-file>layout.xhtml</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
  </servlet-mapping>
</web-app>

layout.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://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html">
    
    <h:head>

        <title>Facelets Template</title>
    </h:head>
    
    <h:body>
            <ui:insert name="footer">Not working</ui:insert>
    </h:body>
</html>

footer.xhtml

<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:ui="http://java.sun.com/jsf/facelets"
      template="layout.xhtml">
	 
	 <ui:define name="footer"> working!!! </ui:define>
</ui:composition>

任何帮助将不胜感激:)

【问题讨论】:

  • 您是否要在 layout.xhtml 中包含 footer.xhtml?
  • 没有@SalihErikci。我试图在 layout.xhtml 中嵌入 footer.xhtml 以显示“工作”。

标签: java html jsf


【解决方案1】:

您应该在 layout.xhtml 中使用 ui:include 来包含 footer.xhtml。

layout.xhtml

<h:head>

    <title>Facelets Template</title>
</h:head>

<h:body>
        <ui:include src="footer.xhtml"/>
</h:body>

footer.xhtml

<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:ui="http://java.sun.com/jsf/facelets"
      template="layout.xhtml">

     <p> working!!! </p>
</ui:composition>

【讨论】:

  • 现在我意识到我的错误了。这是一个误解
猜你喜欢
  • 2021-02-04
  • 2015-06-23
  • 2014-12-26
  • 2013-08-12
  • 2014-06-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多