I've got a template panel.xhtml
which includes itself n
times (n
will be known only in runtime).
panel.xhtml
...
<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>
...
For each panel.xhtml
I want to have a new instance of the controller class PanelController
.
PanelController.java
@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");
}
}
with the ui:param
injected (or obtained in a PostConstruct
method - as it is now).
The problem is that there is only one instance of my controller and this.panel
in it is always the parameter of the last-included template. I understand the controller is view-scoped and is created once per request (roughly speaking). If there was such a thing, @IncludeScoped
would be the solution.
I drew a little representation of what it's happening now, and of what I'd like to get.
Now
What I'm looking for
I was thinking of a custom scope @IncludeViewScoped
. Would it be sensible for my scenario?