You can use the @PostConstruct
annotation to automatically invoke your init method:
@PostConstruct
public void init() {
// do something
}
This method is automatically invoked after construction of the bean.
Your solution looks more like a f:event
with type="preRenderView"
but this can't be used because the c:if
tags are evaluated during view build time, while the f:event
(respectively your solution) runs right before the view is rendered during render response phase. Have a look at this question and this question to get details.
Update: As you commented you are using a @SessionScoped
bean where @PostConstruct
is only called once per session and not on every page load. In this case another solution would be to call your init
method as first statement in your conditionsCheck
method (nearly the same as your suggestion with fake c:if
boolean init). You could also use a custom PhaseListener
but I guess that would be somewhat overdosed for this problem.
See also: