Facelets multi-level templates - ui:define not rendered

独自空忆成欢 提交于 2019-12-29 08:50:49

问题


I have 2 basic templates - one with a side menu, and one without - that both ui:include a common page which contains ui:insert tags (templates are largish, so basic example below).

Using Mojarra everything worked ok, but now I have migrated to MyFaces the ui:insert tags are ignored and the content of the related ui:define does not get rendered (i.e. 'Here are my results' is not displayed).

Should I be specifying included-page.xhtml as a template somehow? I tried

<ui:composition template="included-page.xhtml" />

instead of

<ui:include src="included-page.xhtml" />

but lost the CSS.

Hoping someone can suggest a solution :)

Many thanks,

Neil

my-page.xhtml

<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
    template="/templates/default-template.xhtml">

    <ui:param name="title" value="My Title" />

    <ui:define name="results">

        Here are my results

    </ui:define>

</ui:composition>

default-template.xhtml

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:ui="http://java.sun.com/jsf/facelets">

<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
    <title>#{title}</title>
</h:head>

<h:body>

    <ui:include src="included-page.xhtml" />

</h:body>

</html>

included-page.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets">

    <ui:insert name="results">

    </ui:insert>

</ui:composition>

回答1:


The <ui:include> should have been an <ui:decorate>.

<ui:decorate template="included-page.xhtml" />

But if the included-page.xhtml is by itself not reused elsewhere, I wonder why it isn't just been inlined in the master template instead.

See also:

  • Difference between ui:composition and ui:decorate in Facelets
  • What is the real conceptual difference between ui:decorate and ui:include?


来源:https://stackoverflow.com/questions/13180043/facelets-multi-level-templates-uidefine-not-rendered

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!