Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
541 views
in Technique[技术] by (71.8m points)

java - JSF ui:include not being rendered properly

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

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

1 Reply

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...