Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

jsf - Facelets multi-level templates - ui:define not rendered

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...