Return-Path: X-Original-To: apmail-myfaces-dev-archive@www.apache.org Delivered-To: apmail-myfaces-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 30F5444C4 for ; Sun, 19 Jun 2011 14:46:10 +0000 (UTC) Received: (qmail 21141 invoked by uid 500); 19 Jun 2011 14:46:09 -0000 Delivered-To: apmail-myfaces-dev-archive@myfaces.apache.org Received: (qmail 21098 invoked by uid 500); 19 Jun 2011 14:46:09 -0000 Mailing-List: contact dev-help@myfaces.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "MyFaces Development" Delivered-To: mailing list dev@myfaces.apache.org Received: (qmail 21091 invoked by uid 99); 19 Jun 2011 14:46:09 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 19 Jun 2011 14:46:09 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 19 Jun 2011 14:46:07 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 7AD2F422066 for ; Sun, 19 Jun 2011 14:45:47 +0000 (UTC) Date: Sun, 19 Jun 2011 14:45:47 +0000 (UTC) From: "Leonardo Uribe (JIRA)" To: dev@myfaces.apache.org Message-ID: <1649943249.19209.1308494747500.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <1524636661.9191.1307664598839.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Commented] (MYFACES-3169) ui:param and c:set implementations does not work as expected MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/MYFACES-3169?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13051691#comment-13051691 ] Leonardo Uribe commented on MYFACES-3169: ----------------------------------------- In this case you can do this: Look the additional declaration inside ui:include. In theory, ui:include creates another template context, that means ui:define fragments defined outside it will not be passed. The same happen for ui:param. All params defined outside will be ignored, because those ones are bound to the previous template context. So, ui:param declarations can be lookup on nested ui:composition and ui:decorate tags, but cannot for ui:include. In that case you should declare which params the included page requires, which is preferred because in this way it is easier to see which params are relevant for the template. > ui:param and c:set implementations does not work as expected > ------------------------------------------------------------ > > Key: MYFACES-3169 > URL: https://issues.apache.org/jira/browse/MYFACES-3169 > Project: MyFaces Core > Issue Type: Bug > Components: JSR-314 > Affects Versions: 2.0.7, 2.1.1 > Reporter: Leonardo Uribe > Assignee: Leonardo Uribe > Fix For: 2.0.8, 2.1.2 > > Attachments: MYFACES-3169-2.patch > > > Original message sent to jsr344-experts and users mailing list: > Checking how ui:param and c:set works and its relationship with facelets > VariableMapper, I notice the original implementation that comes from facelets > does not work like a page developer should expect. In fact, in some situations > ui:param and c:set implementation is just the same. > The consequence of this situation is there are ways to write code that just > should not be allowed, because it breaks the intention of those tags. JSF > implementations should fix this, and maybe if it is required add more > documentation specifying these tags better. > The first case is c:set. This is the description on facelets taglibdoc: > "... Sets the result of an expression evaluation based on the value of the > attributes. If 'scope' the is present, but has a zero length or is equal > to the string 'page', TagException is thrown with an informative error > message, ensuring page location information is saved. ..." > "... This handler operates in one of two ways. > 1. The user has set 'var', 'value' and (optionally) 'scope' attributes. > 2. The user has set 'target', 'property', and 'value' attributes. > The first case takes precedence over the second ..." > The buggy behavior of this tag can be seen when it is used in this way: > > Look the part that says "... if 'scope' the is present, but has zero length or > is equal to the string 'page' ..." . In JSP, it exists a page context and > in that context, the variable has scope to the current page. Since in that > case there are no template tags, this variable cannot be located on other > pages included with jsp:include or whatever you use. > The current implementation of c:set that comes from facelets 1.1.x does not > implements the original intention of this tag in jsp, and instead it uses > VariableMapper instance obtained through FaceletContext (which is instance > of ELContext). Since both JSF 2.0 implementations comes from the original > facelets 1.1.x code, you can see the following problems: > cset1.xhtml > > > > > cset1_1.xhtml > > > > The previous code in practice will output "someValue", but it should not, > because "someVar" should be only available on the current .xhtml page, in > this case cset1.xhtml. > Now consider this more realistic example: > cset2.xhtml > > > > > > > > cset2_1.xhtml > > > > > > > > In practice the output will be "badValue", but it should be "someValue", > again because c:set intention is to define a value that should be > available only on the current page. This problem is also valid if you > replace ui tags with a composite component and cc:insertXXX tags. > Now take a look at this one: > cset3.xhtml > > > > > > cset3_1.xhtml > > > > > In practice the output will be again "badValue", but it is interesting to note > that if you use ui:param, the example will work again, because a > VariableMapperWrapper is used, discarding the bad value after ui:decorate > ends. > Things start to get worse when you see how ui:param works: > String nameStr = this.name.getValue(ctx); > ValueExpression valueVE = this.value.getValueExpression(ctx, Object.class); > ctx.getVariableMapper().setVariable(nameStr, valueVE); > > It is the same thing as c:set!!!!! . > if (this.scope != null) > { > /* ... Does this exception really has sense ??? ... */ > if ("page".equals(scopeStr)) > { > throw new TagException(tag, "page scope is not allowed"); > } > /* ... some stuff that works well ...*/ > } else { > ctx.getVariableMapper().setVariable(varStr, veObj); > } > Why this code hasn't been broken before? because nobody has ever use c:set and > ui:param with exactly the same var name. Maybe because on facelets dev > documentation: > http://facelets.java.net/nonav/docs/dev/docbook.html > says this: > "... Table 3.5. (Avoid if Possible) ..." > Really there are some particular situations where c:set is useful. > There are a lot more examples I tried on ui:param that just don't work. But > the big question is how c:set and ui:param should work? > - c:set using only 'var' and 'value' should define the variable only as > "page" scoped, just like the old jstl tag does and the current spec javadoc > says. > - ui:param should define a variable "template" scoped, that means it applies > to both template client and templates. It should be propagated through > ui:composition, ui:decorate, ui:define and ui:insert, but it should not pass > composite components, because this one defines a different template resolution > context (hack only on MyFaces, but valid for JSF). It should not pass on > nested templates case (nested ui:composition or ui:decorate). > - The facelets taglibdoc of ui:param says: > "... Use this tag to pass parameters to an included file (using ui:include), > or a template (linked to either a composition or decorator). Embed ui:param > tags in either ui:include, ui:composition, or ui:decorate to pass the > parameters. ..." > JSF implementation should do exactly what it says here. > Note all this should work using a more elaborate hack over VariableMapper, > because it is not possible to use another alternative here. One idea is > create a component that defines a "local" page scope just like {} does > in java code, but maybe is too much for something than in practice should > be simple. > I think this should be fixed. Obviously I'm doing an interpretation of the > few documentation available, but note at the end a "final word" should be > done here at spec level to keep compatibility between JSF implementations. -- This message is automatically generated by JIRA. For more information on JIRA, see: http://www.atlassian.com/software/jira