0

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

<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: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.

@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.

Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142
  • @Selaron sorry, isn't it Java? – Andrew Tobilko Jun 13 '19 at 08:43
  • No problem - there's java used, yes, but a java language expert still won't be able to answer a JSF specific question. – Selaron Jun 13 '19 at 08:53
  • @BalusC I'd greatly appreciate it if you had a look at this – Andrew Tobilko Jun 13 '19 at 08:56
  • 1
    So you would like to access your `ui:param` value from within a bean `@PostConstruct` initializer without that workaround described in your question? If so I think this might answer your question: [How to access ui:param value in the managed bean](https://stackoverflow.com/questions/12533865/how-to-access-uiparam-value-in-the-managed-bean#12534709) – Selaron Jun 13 '19 at 09:00
  • @Selaron yes, it seems to work for me. I am wondering why getting include params is "implementation dependent"... – Andrew Tobilko Jun 13 '19 at 13:49

0 Answers0