开发者

Why does ui:Include behavior vary with different bean scopes?

I have been tinkering around with ui:include lately and have found it to be fairly quirky in many of its behaviors. After a some testing, it seems to me like these quirks have to do with issues go back to 开发者_如何学JAVAhow ui:include fits into the jsf lifecycle. I am trying to get a better grasp on the framework, and was wondering if anyone could help me understand what is going on.

Take the following example:

index.xhtml

<h:panelGrid id="testInclude">
    <ui:include src="#{bean.pageTarget}.xhtml" />
</h:panelGrid>

bean (ManagedBean, SessionScoped)

public String getPageTarget() { return "pageA"; }
@PostConstruct
public void init() { System.out.println("new bean created"); }

pageA.xhtml

<ui:composition>
    <h:outputText value="You are on page: #{bean.pageTarget}" />
</ui:composition>

When the page is first rendered, two bean instances are created. This is directly related to there being a reference to bean in pageA. Based on one of BalusC's previous answers, this probably has to do with when ui:include is processed: dynamic ui:include with el-expression?

The curious thing is that changing bean to use CDI's conversation scope actually gets rid of this problem. Does anyone know why this works?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜