我有一个模板panel.xhtml
,其中包含n
次(n
仅在运行时才知道)。
...
<c:when test="#{condition}">
<!-- include other panels -->
<ui:include src="panel.xhtml">
<ui:param name="panel" value="#{otherPanel}"/>
</ui:include>
</c:when>
</c:otherwise>
<!-- render the content of the panel -->
<c:otherwise>
...
对于每个panel.xhtml
,我想要一个控制器类PanelController
的新实例。
@ViewScoped
@ManagedBean(name = "panelCtrl", eager = true)
public final class PanelController {
private Panel panel;
@PostConstruct
public void initialise(Panel panel)
{
panel = (Panel) ((FaceletContext) FacesContext.getCurrentInstance().getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY)).getAttribute("panel");
}
}
注入了ui:param
(或通过PostConstruct
方法获得-现在是这样)。
问题在于我的控制器只有一个实例,其中的this.panel
始终是最后包含的模板的参数。我了解控制器是基于视图的,并且每个请求都会创建一次(大致而言)。如果发生这种情况,@IncludeScoped
将是解决方案。
我对现在正在发生的事情以及我想要得到的东西做了一点表示。
我正在考虑自定义范围@IncludeViewScoped
。对我的情况明智吗?