I've got a page which includes x.xhtml
and passes 2 ui:param
s.
<p:outputPanel>
<ui:include src="x.xhtml">
<ui:param name="a" value="a" />
<ui:param name="b" value="b" />
</ui:include>
</p:outputPanel>
x.xhtml
, at the beginning of itself, declares 2 c:set
s which set the parameters into a @ViewScoped
controller called current
.
<c:set target="#{current}" value="#{a}" property="a" />
<c:set target="#{current}" value="#{b}" property="b" />
setA(A a)
and setB(B b)
methods will be called to set these properties.
@ViewScoped
class CurrentViewController {
private A a;
private B b;
public void setB(B b) { this.b = b; }
public void setA(A a) { this.a = a; }
}
I am looking for a place in my controller where both parameters would be ready. I don't need them to be properties. They are supposed to initialise the controller. I'd rather not use them in the template. I'd rather not have them as fields. I'd rather remove the setters.
The problem is they aren't accessible from a constructor, a @PostConstruct
method, or any other mechanism I am aware of. They are accessible in corresponding setters, but separately.
public void setB(B b) {
// I have to check if this.a is already set
if (this.a != null) {
// I can do my initialisation: this.a and b are ready
}
// I have to set a field because setA would do the same trick
}
setA(A a)
would look as ugly as setB(B b)
is. It's also unclear which method triggers the initialisation. I guess it mainly depends on the order of parameters in ui:include
.