title: Observer and JSF ManagedBean
body: <p>I have a drop down menu from which user selects an item(in my case project he is working on), most of the data displayed by a webpage depends on that selection. So I have couple of view scoped beans that call EJB beans which do database queries that depend on the selected project.</p>
  
  <p>I want to cache most of that data in order to reduce Database queries, but when user changes project it has to notify other beans that change has happened and new data needs to be fetched.</p>
  
  <p>So I had an idea:</p>
  
  <ul>
  <li><p>projectChangeManager (session scoped managed bean), saves which project is selected, notifies it's subscribers when project changes. Has @PreDestory method implemented where I cleanup observers.</p></li>
  <li><p>project observers (view scoped managed beans), gets data from EJB based on project selection, has onProjectChange() method which fetches new data from EJB. Has @PreDestory method implemented where projectChangeManager.detach(this) is called to unsubscribe from projectChangeManager.</p></li>
  </ul>
  
  <p>Is this reasonable approach in JSF? Or is it better not to implement observer pattern but just when user changes project I fetch all cached data and save it in session bean and then in ViewScoped bean I just access that data from SessionScoped bean? Or is there a better way?</p>