문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top