[ https://issues.apache.org/jira/browse/MYFACES-4440?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17597144#comment-17597144 ]
Thomas Andraschko commented on MYFACES-4440: -------------------------------------------- ahh i think i better understood this now i dont think "transient" is inherited from the template to the views per spec or is this something mojarra implemented? > MyFaces forces session creation when transient=true if using ui:composition > --------------------------------------------------------------------------- > > Key: MYFACES-4440 > URL: https://issues.apache.org/jira/browse/MYFACES-4440 > Project: MyFaces Core > Issue Type: Bug > Affects Versions: 2.3.10 > Reporter: Jonathan S. Fisher > Priority: Minor > > Hello, we noticed a small bug with transient="true" on a f:view. Essentially, > if you use Facelets templating, you always get a session created. > Near the end of RenderResponseExecutor.execute(), it calls a private function > called forceSessionCreation(). This is done because if the view is > non-transient, you need to get the cookie header out the door before any > rendering is done that could possible using a viewScopedBean. Makes sense. > Here's the bug we noticed though, if the xhtml file uses ui:composition, the > transient flag is false at that point. This forces a sessionCreation even > though later the setTransient is set on the viewRoot. I'm probably not using > the correct terminology above, so an example is probably just a better way to > demonstrate the problem: > Lets say this is your index.xhtml: > {{<ui:composition}} > {{ xmlns="http://www.w3.org/1999/xhtml"}} > {{ xmlns:h="http://xmlns.jcp.org/jsf/html"}} > {{ xmlns:ui="http://xmlns.jcp.org/jsf/facelets"}} > {{ xmlns:mf="https://emoneyusa.com/magfaces/1.0/ui"}} > {{ template="/template.xhtml">}} > {{ <ui:define name="body">this creates a session</ui:define name="body">}} > {{</ui:composition>}} > and this is your template.xhtml > {{<html xmlns:f="http://xmlns.jcp.org/jsf/core">}} > {{ <f:view}} > {{ contentType="text/html"}} > {{ encoding="UTF-8"}} > {{ transient="true">}} > {{ <h:head><title>template title</title></h:head>}} > {{ <h:body>}} > {{ <ui:insert name="body"/>}} > {{ </h:body>}} > {{ </f:view>}} > {{</html>}} > Whats interesting is if you do not use Facelets Templates, everything works > just fine. My naive analysis thinks that when the VDL creates a UiViewRoot, > the transient flag is not set correctly at that point. > My team has pushed a few patches to MyFaces over the last year, and we're > happy to take a crack at this one too! For us, simply removing the check > context.getViewRoot().isTransient() in forceSessionCreation is sufficient to > solve the problem, but we know that pretty much nerfs that function of its > intended purpose. We love MyFaces and are happy to put in some sweat to fix > bugs like this that affect everyone. As such, we could use a bit of guidance > on the preferred fix. It seems setTransient() needs to be called much sooner, > and we're not sure how to accomplish that. > Thank you! > EDIT: > As a workaround, one can wrap ui:composition in f:view which seems to work > (although we're not sure it's supposed to... a view in a view?): > {{<f:view}} > {{ xmlns="http://www.w3.org/1999/xhtml"}} > {{ xmlns:f="http://xmlns.jcp.org/jsf/core"}} > {{ xmlns:h="http://xmlns.jcp.org/jsf/html"}} > {{ xmlns:ui="http://xmlns.jcp.org/jsf/facelets"}} > {{ contentType="text/html"}} > {{ encoding="UTF-8"}} > {{ transient="true">}} > {{ <ui:composition template="/template.xhtml">}} > {{ <ui:define name="body">Hello! No session created</ui:define>}} > {{ </ui:composition>}} > {{</f:view>}} -- This message was sent by Atlassian Jira (v8.20.10#820010)