【问题标题】:JSF <include> doesn't work in templateJSF <include> 在模板中不起作用
【发布时间】:2014-06-11 01:21:16
【问题描述】:

我是 Java 和 JSF 的新手,正在尝试使用 JSF 模板 &lt;ui:include&gt;&lt;ui:insert&gt; 创建测试页面。结果,我在页面上只得到了&lt;ui:insert&gt; 块,但没有呈现&lt;ui:include&gt;。有人可以建议这里有什么问题吗?这是我的模板main_template.xhtml

<?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 lang="en"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html">
    <h:head>
        <title>Title Here</title>
    </h:head>
    <h:body>
        <div id="header">
            <ui:include src="header.xhtml"/>
        </div>
        <div>
            <div id="menu">
                <ui:insert name="menu">Menu string</ui:insert>
            </div>
            <div id="content" >
                <ui:insert name="content">Main Content</ui:insert>
            </div>
        </div>
    </h:body>
</html>

这里是index.xhtml

<ui:composition template="WEB-INF/templates/main_template.xhtml"
     xmlns="http://www.w3.org/1999/xhtml"
     xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
     xmlns:h="http://xmlns.jcp.org/jsf/html">

    <ui:define name="menu">
        <h1>Menu will be here</h1>
    </ui:define>

    <ui:define name="content">
        <h1>New content here</h1>
        <p>Blah blah</p>
    </ui:define>
</ui:composition>

..和header.xhtml:

<ui:composition 
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html">
    <h2>Header page</h2>
    <p>Include page blah blah lorem ipsum</p>
</ui:composition>

【问题讨论】:

  • 如果 header.xhtml 和 main_template.xhtml 存储在不同的文件夹中,则需要在ui:include 中设置正确的 header.xhtml 路径。如果它在同一个文件夹中,请尝试使用&lt;ui:include src="/WEB-INF/templates/header.xhtml" /&gt;

标签: java jsf jsf-2 include


【解决方案1】:

在定义模板文件时,您在WEB-INF 之前错过了/

<ui:composition 
                template="/WEB-INF/templates/main_template.xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
                xmlns:h="http://xmlns.jcp.org/jsf/html">
</ui:composition>

【讨论】:

  • 我尝试了使用/和不使用/,结果是一样的
  • 不,我没有。 &lt;ui:include&gt; html 根本不存在于页面上。
  • 你的jsf 版本是什么?
  • @mav3r1ck 如果&lt;ui:include&gt; 不起作用,您是否收到Menu string 文本您在template file 中定义的内容?
  • Menu Stringinsert 之内,它可以正常工作并显示define 中的内容。 JSF 2.2
猜你喜欢
  • 2017-02-07
  • 1970-01-01
  • 2023-03-25
  • 1970-01-01
  • 2018-07-18
  • 1970-01-01
  • 2017-05-27
  • 2013-06-07
  • 2015-07-06
相关资源
最近更新 更多