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

Categories

I'm implementing a web application using JSF 2.1.8 and I have a problem with the ui:include tag. I have this code

<h:panelGroup id="panelContenido">

        <ui:fragment rendered="#{!empty navigationManagerSystem._Navegable}">
            <ui:include src="#{navigationManagerSystem._Navegable._IncludePath}" />

        </ui:fragment>
        <ui:fragment rendered="#{empty navigationManagerSystem._Navegable}">
            <ui:include src="/system/navigation/error.xhtml" />
        </ui:fragment>
    </h:panelGroup>

The navigationManagerSystem bean is JSF session managed and when this piece of code is firstly rendered, it is supposed to show the include path content. This include works if I do it in a constant like that <ui:include /system/home/index.xhtml" /> but not if I put it in the variable, even I have seen the variable is holding that value before the screen prints. I don't know if it can be related with the bean that holds /system/home/index.xhtml page, which is View Scoped.

Anyway, if I do a page refresh just after page rendering, the xthml is properly included. By the way, I have simplified the page to be included in order to not have any jstl tags, because I know they can cause problems with View Scope.

Any idea about that?

See Question&Answers more detail:os

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

1 Answer

As to the cause of the problem, the <ui:include> runs during view build time (restore view phase) not during view render time (render response phase) as you seem to expect. So if the include path changes during for example invoke action phase or even render response phase, then it won't be reflected in the view unless it's completely rebuilt.

Currently, your best bet is to use multiple static <ui:include> tags which are each conditionally rendered during view render time. True, this ends up with an unnecessarily large component tree. There is still no "holy grail" solution for this problem. The problem is clearly understood, but the solution is hard given the JSF/Facelets lifecycle. I have for OmniFaces done some experiments on that as well, however the simplest attempt fails hard in MyFaces while it works (to certain degree) in Mojarra.

See also:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...