Neeraj
Neeraj

Reputation: 155

View scoped bean is not getting destroyed

I am using JSF 2.1 and primefaces 3.4.

All my xhtml views consist of layout which has header,left side navigation panel,footer and content.The managed beans are in view scope.

In most of my views, I am using f:event listener of type preRenderView to intialize certain attributes and services. In the listener, I have conditional statement to check for postback request. It exceutes the complete code inside preRenderView listener only when the request is not postback.

Even if I navigate to any other page (from let's say page A to page B) via left side navigation panel link, the view scope doesn't get destroyed and when I again return back to page A, the check for postback request returns true.Not sure why it is happening.

Appreciated if someone can help me?

Thanks in advance.

Upvotes: 2

Views: 1755

Answers (1)

BalusC
BalusC

Reputation: 1109272

You need to navigate by GET instead of POST.

I.e., use <h:link> or <h:button> instead of <h:commandLink> or <h:commandButton> for plain page-to-page navigation. This way the isPostback() will return false.

Further, you're not clear on how you've observed that the view scoped bean is not getting destroyed. Have you placed a debug breakpoint on bean's constructor to see if it's invoked when the new page is requested? If it is really exactly the same instance, then that can only happen if you're actually conditionally including a new page instead of really navigating to a physically different view.

Upvotes: 1

Related Questions