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

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

Use extendClient(this) instead pushClient(this) changes the semantic of the 
algorithm. 

The important to keep in mind here is the "precedence", in other words, which 
TemplateClient should be applied first.

I'll do a full review to explain what's happening and what is the intention, 
because sometimes is not easy to "put all pieces in places".



A TemplateClient is a tag handler or class that exposes "fragments" or 
"definitions". Right now, some tag handlers used by composite component stuff 

uses TemplateClient too, but I'll ignore them for now. 

Which classes implement TemplateClient for template mechanism?

- ui:decorate    : DecorateHandler
- ui:insert      : InsertHandler
- ui:composition : CompositionHandler

ui:insert expose automatically a definition, but ui:composition and ui:decorate 
expose multiple definitions using ui:define tag.

Note ui:composition has two different behaviors

- If ui:composition has no template, it is just used to trim everything outside 
it.
- If ui:composition has template, it is used to contain a set fo definitions 
created by ui:define.

The current algorithm could be seen as a stack of TemplateClient. It is based 
on two calls:

- TemplateContext.extendClient : put a TemplateClient at the bottom of the 
stack.
- TemplateContext.pushClient   : put a TemplateClient at the top of the stack.

Why this is important? because the algorithm to resolve a definition 
(TemplateContext.includeDefinition() ), just traverse all template clients from 

top to bottom trying to find the first one that resolves it valid.

Which classes uses extendClient ? InsertHandler and CompositionHandler. 

Which classes uses pushClient ? DecorateHandler and UserTagHandler (facelets 
tags defined in xhtml files uses it)

What is the underlying idea? All occurences of ui:insert happen on the 
template, so it should be resolved at last. When a templated ui:composition is 

found, the template is resolved first, so when it founds ui:insert, try to find 
if the previous template client (in that case ui:composition) has a 

definition that can resolve it and if so, it insert it.

ui:decorate uses pushClient to override all definitions, so that's the reason 
why it is set on top. The same effect is required in UserTagHandler, 

because it is necessary this effect here too.



Now let's take a look at the problem. Taking into account the previous 
explanation, it is clear why the previous test fails. Look the first template:

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> 

What's wrong? ui:decorate is set on top of the stack, so if ui:include has a 
template, the definition on ui:decorate is taken into account. So, in 

this place we need to do the same as we did on a composite component template 
client solution and it is already in myfaces: isolate the template context, 
creating a new one and put it on the template context stack.

 I didn't found a counter-example that shows why don't do this fix yet. Note 
this fix is risky, so it is preferred to do a release first and include this 
fix on the next one. I think this issue is of interest of the EG, so we need to 
get some feedback from there first before do anything.

I think the best for this issue is take our time to solve it and don't commit 
anything until do the previous process.

Suggestions are welcome.



> 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-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