The right way to initialise a JSF controller with ui:params

by Andrew Tobilko   Last Updated June 13, 2019 08:26 AM

I've got a page which includes x.xhtml and passes 2 ui:params.

    <ui:include src="x.xhtml">
        <ui:param name="a" value="a" />
        <ui:param name="b" value="b" />

x.xhtml, at the beginning of itself, declares 2 c:sets 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.

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
Tags : java jsf jsf-2.2

Related Questions

Updated January 09, 2018 04:26 AM

Updated November 04, 2017 02:26 AM

Updated November 17, 2018 17:26 PM