Question

I have a menu with items that point to different views.

Each view has a select combo box with an attached listener.

In that views I use session-scoped managed beans.

When I navigate to a view for the first time, a method is called when the bean is constructed. The same method is called when the user changes the value from the select box. But the method doesn't get called when the view is redisplayed.

This happens because I use session-scoped beans. A better solution would have been to use view-scoped beans instead, but I am looking for an alternative. Is there a way to execute certain code when a view changes?

Was it helpful?

Solution

You can use <f:event> wherein you attach a listener method to preRenderView event.

E.g.

<f:event type="preRenderView" listener="#{bean.preRenderView}" />

with

public void preRenderView() {
    // ...
}

This will be invoked everytime in the beginning of the render response phase.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top