0 Replies Latest reply on Mar 29, 2008 11:22 AM by Thiagu Mariappan

    Issue in using Seam blog example for implementing dynamic ca

    Thiagu Mariappan Novice

      Hello everyone,

      I need to display a large dataset within a dynamic page with a good response time.
      So I am trying to use the page fragment cache. (s:cache). The cache works, but I can’t prevent the query from executing on subsequent attempts.

      I have reviewed the seam blog example and it has the code to prevent the query from repeatedly executing. What they did is they did not invoke any method at time we go to cached page.
      The dataTable invokes the method and gets the data. After that it uses the same data for display, otherwise the cache is flushed.

      The issue I have is that the blog example shows how to do it for a static query, but I have a dynamic query so that I can fetch data depending on the parameter that I have passed. The first page is a list of categories, and the second page is a listing of products in a specific category and the parameter categoryid is passed from the first page to second page to fetch the data.

      The parameter can take any one of 16 values, so I need to maintain the 16 caches for a single page, based on parameter id.

      How can this be accomplished? What is the correct approach to take in my case for caching? Would greatly appreciate any pointers on how this can be done.

      This is my home page code (Home.xhtml )

      <s:link value="Cell phone" action="#{search.select}" view="/table.xhtml" >
       <f:param name="hid" value="2"/>
       <s:link value="Digital" action="#{search.select}" view="/table.xhtml" >
       <f:param name="hid" value="9"/>

      This is my second page code (table.xhtml)
      <s:cache key="{hid)" region="pageFragments">
       <rich:dataTable value="#{productList}" var="category">
       <f:facet name="header">
       <h:outputText value="Product Name" />
       <h:outputText value="#{category.productName}" />
       <f:facet name="header">
       <h:outputText value="Price" />
       <h:outputText value="#{category.price}" />

      This is my session bean code
      public class HomeAction implements Home,Serializable
       BigDecimal hid;
       EntityManager em;
       List<TblProducts> productList;
       public void select() {
       if (hid != null)
       productList = em.createQuery("select b from TblProducts b where b. categoryid ="+ hid) .setHint("org.hibernate.cacheable", true).getResultList();
       public void destroy() {}