title: Real time updates from database using JSF/Java EE
body: <p>I have one application running in the following environment.</p>
  
  <ul>
  <li>GlassFish Server 4.0</li>
  <li>JSF 2.2.8-02</li>
  <li>PrimeFaces 5.1 final</li>
  <li>PrimeFaces Extension 2.1.0</li>
  <li>OmniFaces 1.8.1</li>
  <li>EclipseLink 2.5.2 having JPA 2.1</li>
  <li>MySQL 5.6.11</li>
  <li>JDK-7u11</li>
  </ul>
  
  <p>There are several public pages which are lazily loaded from the database. A few CSS menus are displayed on the header of the template page like displaying category/subcategory-wise featured, top seller, new arrival etc products.</p>
  
  <p>The CSS menus are populated dynamically from the database based on various categories of products in the database.</p>
  
  <p>These menus are populated on every page load which is completely unnecessary. Some of these menus require complex/expensive JPA criteria queries.</p>
  
  <p>Currently the JSF managed beans that populate these menus are view scoped. They all should be application scoped, be loaded only once on application start up and be updated only when something in the corresponding database tables (category/subcategory/product etc) is updated/changed.</p>
  
  <p>I made some attempts to understand WebSokets (never tried before, completely new to WebSokets) like <a href="https://netbeans.org/kb/docs/javaee/maven-websocketapi.html">this</a> and <a href="http://www.hascode.com/2013/08/creating-a-chat-application-using-java-ee-7-websockets-and-glassfish-4/">this</a>. They worked fine on GlassFish 4.0 but they don't involve databases. I'm still not able to understand properly how WebSokets work. Especially when database is involved.</p>
  
  <p>In this scenario, how to notify the associated clients and update the above-mentioned CSS menus with the latest values from the database, when something is updated/deleted/added to the corresponding database tables?</p>
  
  <p><sub>A simple example/s would be great.</sub></p>