[ 
https://issues.apache.org/jira/browse/MYFACES-2753?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12891733#action_12891733
 ] 

Leonardo Uribe commented on MYFACES-2753:
-----------------------------------------

Hi Jakob

The idea behind the test is define the "correct" mechanism. I want to have a 
"position" about how this should work before discuss. With the tests already 
provided it is possible to try to change the current algorithm and see the 
effect of the changes. I'm trying to "imagine" why the original author of 
facelets did this in this way. I'll describe in deep why I think ui:composition 
should work as is (most of the stuff you already know but I provide it so other 
people know what's going on).

In theory, a template is a page written in a xml markup with multiple ui:insert 
"spots" when we can insert "fragments" or "definitions" of more markup. The 
document titled facelets developer documentation that you have already read 
says this (section 5):

"..... When describing templating within Facelets, we have two roles: the 
template and the template client.

Any document can act as a template; but what makes a document a template? It 
just simply uses one or more <ui:insert/> tags to inject content from another 
source. ......"

So a template could be something similar to this:

<html ......>
<body>
<!-- .... html markup -->
<ui:insert name="fragment1">
fragmentNumber1
</ui:insert>
<!-- .... html markup -->
</body>
<html>

So, what is a template client?

"....A template client can break up its body within multiple, named <ui:define> 
 tags..."

We can put ui:define tags inside ui:composition, ui:decorate and user tag 
handlers. The idea behind this concept is replace the content inside ui:insert 
tags on the template.

"... 5.1.3. Multi-Level Templating

Template use may go multiple levels deep. This means that a template client may 
use a template which in turn may use a template, which may also use a template, 
and then it may use yet another template... you get the picture.

Templating is backed by the a TemplateManager that has a stack of 
TemplateClient instances. Tags like <ui:composition> implement TemplateClient. 
When a template is being evaluated and comes upon a <ui:insert/> tag, it will 
ask the TemplateManager for a TemplateClient that either has a match for the 
tag's name attribute, or the top-most TemplateClient on the stack.

An example would be having a <ui:insert name="title"/> tag in the template. The 
TemplateManager will walk through its internal stack of TemplateClients, asking 
each one for a content under the name title. It will continue through the stack 
until one is found. If none are found, then the original template is free to 
include the default content. See Section 5.9, "<ui:insert/>" for more 
information on default content. ...."

ui:composition is a template client. So the following markup:

<ui:composition template="/template1.xhtml">
<ui:define name="fragment1">
fragmentNumber1
</ui:define>
</ui:composition>

Says that we need to execute the template but replace the definition of 
fragment1 with fragmentNumber1. If we reference the previous page in this way 
again:

<ui:composition template="/composition4.xhtml">
<ui:define name="fragment1">
fragmentNumber2
</ui:define>
</ui:composition>

Says that we need to execute the template but replace the definition of 
fragment1 with fragmentNumber2. The top-most TemplateClient on the stack is the 
first one to be resolved, so according to the original intention of the author 
it is expected fragmentNumber2 be the response and not fragmentNumber1.

Now, for ui:decorate, checking facelets issue tracker I found this issue:

https://facelets.dev.java.net/issues/show_bug.cgi?id=256

When this issue was solved, the difference between ui:composition and 
ui:decorate was set. I include a test for this one in the test case. 

I hope the previous explanation makes clearer the position about this issue.

regards,

Leonardo


> Trivial multi-level templating does not work if ui:include is used
> ------------------------------------------------------------------
>
>                 Key: MYFACES-2753
>                 URL: https://issues.apache.org/jira/browse/MYFACES-2753
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: JSR-314
>    Affects Versions: 2.0.2-SNAPSHOT
>         Environment: myfaces core trunk (2.0.2-SNAPSHOT), tomcat 6.0.26
>            Reporter: Martin Kočí
>            Assignee: Jakob Korherr
>         Attachments: MYFACES-2753-TestCase-FixInclude.patch, 
> MYFACES-2753-tests.patch, MYFACES-2753.patch, MYFACES-2753.tar.gz
>
>
> Following example does not produce any output:
> OuterClient.xhtml
> <ui:decorate
>     template="/templates/OuterTemplate.xhtml"
>     xmlns:ui="http://java.sun.com/jsf/facelets";>
>     <ui:define name="content">
>         <ui:include src="InnerClient.xhtml" />
>     </ui:define>
> </ui:decorate>
> OuterTemplate.xhtml:
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
> "http://www.w3.org/TR/html4/loose.dtd";>
> <html
>     xmlns="http://www.w3.org/1999/xhtml";
>     xmlns:ui="http://java.sun.com/jsf/facelets";
>     xmlns:f="http://java.sun.com/jsf/core";
>     xmlns:h="http://java.sun.com/jsf/html";>
> <f:view>
>     <h:head>
>         <title>title</title>
>     </h:head>
>     <h:body>
>         <ui:insert name="content" />
>     </h:body>
> </f:view>
> </html>
> InnerClient.xhtml:
> <ui:composition
>     template="/templates/InnerTemplate.xhtml"
>     xmlns="http://www.w3.org/1999/xhtml";
>     xmlns:ui="http://java.sun.com/jsf/facelets";>
>     <ui:define name="content">
>         Do you see me?
>     </ui:define>
> </ui:composition>
> InnerTemplate.xhtml:
> <f:subview
>     xmlns:ui="http://java.sun.com/jsf/facelets";
>     xmlns:f="http://java.sun.com/jsf/core";>
>     <ui:insert name="content" />
> </f:subview>
> But if OutterClient.xhtml looks like:
> <ui:decorate
>     template="/templates/OuterTemplate.xhtml"
>     xmlns:ui="http://java.sun.com/jsf/facelets";>
>     <ui:define name="content">
>         <ui:composition template="/templates/InnerTemplate.xhtml">
>             <ui:define name="content">
>                 Do you see me?
>             </ui:define>
>         </ui:composition>
>     </ui:define>
> </ui:decorate>
> it outputs "Do you see me?" which is expected result in both cases. I think 
> first case should work too - or am I missing something?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to