代码之家  ›  专栏  ›  技术社区  ›  Shervin Asgari

在Facelets中使用include时出现问题

  •  11
  • Shervin Asgari  · 技术社区  · 15 年前

    所以我改了密码:

    <!DOCTYPE html>
    <ui:composition 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"
        template="/layout/template.xhtml">
    
        <ui:define name="head">
            <title>Title</title>
        </ui:define>
    
        <ui:define name="header">
            <h3>Header</h3>
        </ui:define>
    
        <ui:define name="content">
            <table><tr><td>table</td></tr></table>
        </ui:define>
    </ui:composition>
    

    对此:

    <!DOCTYPE html>
    <ui:composition 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"
        template="/layout/template.xhtml">
    
        <ui:define name="head">
            <title>Title</title>
        </ui:define>
    
        <ui:include src="/admin/admin_generic.xhtml"/>
    </ui:composition>
    

    admin-generic.xhtml 我将代码包装在一个ui:composition中。

    <ui:composition 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">
    
        <ui:define name="header">
            <h3>Header</h3>
        </ui:define>
    
        <ui:define name="content">
            <table><tr><td>table</td></tr></table>
        </ui:define>
    </ui:composition>
    

    但什么也没显示。我只得到一个空白页,没有错误。用错了吗 ui:composition ui:component 但这也没用。


    :根据我的Facelets Essentials指南,它说:

    这个 ui:include 标记可用于将另一个Facelets文件包含到 文件。它只包括您指定的任何源文件。你可以 用户界面:组件 用户界面:合成 标签 或者只是 XHTML或XML。

    2 回复  |  直到 15 年前
        1
  •  11
  •   BalusC    15 年前

    这个 <ui:define> 必须放在 <ui:composition> <ui:decorate> 具有 template 包含适当的 <ui:insert> 标签。你把它移到了 <ui:组成> 没有 . 没有模板意味着没有内容。

    从技术上讲,要达到您的要求,您必须替换 <ui:include> <用户界面:插入>

    <!DOCTYPE html>
    <ui:composition
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        template="template.xhtml">
    
        <ui:define name="head">
            <title>Title</title>
        </ui:define>
    
        <ui:insert />
    </ui:composition>
    

    并声明上一页(我认为 somepage.xhtml )作为 模板 admin_generic.xhtml .

    <!DOCTYPE html>
    <ui:composition
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        template="somepage.xhtml">
    
        <ui:define name="header">
            <h1>Header</h1>
        </ui:define>
    
        <ui:define name="content">
            <table><tr><td>table</td></tr></table>
        </ui:define>
    </ui:composition>
    

    注意你必须打开 而是在浏览器中。如果你想打开 somepage.xhtml文件 在浏览器中,然后 <用户界面:定义> 真的必须呆在家里 somepage.xhtml文件 < 通过一个简单的 < .

    <!DOCTYPE html>
    <ui:composition 
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        template="template.xhtml">
    
        <ui:define name="head">
            <title>Title</title>
        </ui:define>
    
        <ui:define name="header">
            <h1>Header</h1>
        </ui:define>
    
        <ui:define name="content">
            <ui:include src="admin_generic.xhtml" />
        </ui:define>
    </ui:composition>
    

    <ui:组成> ,所以你不必把 <table> 扎根。

    <!DOCTYPE html>
    <ui:composition 
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets">
    
        <table><tr><td>table</td></tr></table>
    </ui:composition>
    
        2
  •  1
  •   Shervin Asgari    15 年前

    <ui:composition> 以及 <ui:define> 直接在 <table> 这样地:

    <table class="adminform" xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a="http://richfaces.org/a4j">
    

    <ui:define name="content">
        <ui:include src="/admin/admin_generic.xhtml" />
    </ui:define>