7 Replies Latest reply on Jul 13, 2011 4:12 PM by Val Sw

    Avoid loading all data from seam-gen default entity list...

    Val Sw Expert
      Hi,

      I am looking for the best way to handle this....

      Seam-gen generated the list page (ItemList.xhtml), with corresponding entity query list object (ItemList.java).

      When user clicks on ItemList.xhtml from header menu, by default all records are loaded in datatable.... I also noticed getItem is called many times on clicking ItemList.xhtml

      Please suggest what will be the best approach to handle this, to first show no result datatable, and display records only after user clicks Search.

      ItemList.java
      @Name("itemList")
      public class ItemList extends EntityQuery {
           
           private static final String[] RESTRICTIONS = {"lower(item.itemName) like concat('%',lower(#{itemList.item.itemName}),'%')",};

           private Item item = new Item();

           @Override
           public String getEjbql() {
                return "select item from Item item";          
           }

           @Override
           public Integer getMaxResults() {
                return 25;
           }

           public Item getItem() {
                //THIS IS CALLED MULTIPLE TIMES
                return item;
           }

           @Override
           public List<String> getRestrictions() {
                return Arrays.asList(RESTRICTIONS);
           }

      }

      Regards
        • 1. Re: Avoid loading all data from seam-gen default entity list...
          omid pourhadi Apprentice

          I recommend set render dataTable default value to false and after user clicks on search set render value to true

          • 2. Re: Avoid loading all data from seam-gen default entity list...
            Val Sw Expert
            Thanks for the response...

            Does it mean that I should change rendered="#{not empty itemList.resultList}" to false by default (from some backing bean), then set it to true once user click "Search".

            But, still I can see getItem is called lot of times...
            public Item getItem() {
              System.out.println("ItemList.getItem()");//THIS IS CALLED MULTIPLE TIMES
              return item;
            }

            xhtml code:
            <rich:dataTable id="itemList"
                            var="item"
                          value="#{itemList.resultList}"
                       rendered="#{not empty itemList.resultList}">
                           
                   <h:column>
                        <f:facet name="header">
                            <s:link styleClass="columnHeader"
                                         value="Item Name #{itemList.order=='itemName asc' ? messages.down : ( itemList.order=='itemName desc' ? messages.up : '' )}">
                                <f:param name="order" value="#{itemList.order=='itemName asc' ? 'itemName desc' : 'experimentName asc'}"/>
                            </s:link>
                        </f:facet>
            .....
            </rich:dataTable>
            • 3. Re: Avoid loading all data from seam-gen default entity list...
              Val Sw Expert

              Any suggestions...


              I have read some posts bit it is not clear...


              Please advice.

              • 4. Re: Avoid loading all data from seam-gen default entity list...
                Roger Mori Newbie

                Hi Val Sw:


                Your itemList.getItem method is called a many times it appears in your EL code, being the normal-and-nothing-wrong-with-it behavior.


                My solution is working trough the sub class (extending EntityQuery) listed below, which triggers on/off the query via a parameter called openFire. You have to explicitily declare/send the parameter on the the menu, page descriptor, and each link/button tag that renders the view. You need only the methods annotated with @Override.


                Roger.


                package com.dpn.action.sf;
                
                import java.util.List;
                
                import org.jboss.seam.annotations.Logger;
                import org.jboss.seam.framework.EntityQuery;
                import org.jboss.seam.log.Log;
                
                import com.dpn.action.ui.ColumnOrder;
                public class HerlindaQuery<E> extends EntityQuery<E> {
                     private static final long serialVersionUID = 1L;
                     
                     @Logger 
                     protected Log log;
                     
                     private Boolean openFire;
                     protected  ColumnOrder columnOrder = new ColumnOrder();       
                          
                      private int counter;     
                       @Override
                       protected javax.persistence.Query createQuery(){
                            log.info("Query has been created {0} times", ++counter);
                            //javax.persistence.Query $query =  super.createQuery();
                            //log.info(this.getRenderedEjbql());
                            return super.createQuery();
                       }
                
                     
                        
                        
                        public void wireColumnOrder() {
                                log.info("orderColumn has been called");
                                if (columnOrder.getItems().isEmpty()) {
                                     log.info("No columns have been selected");
                                     return;
                                }
                                String $order = columnOrder.getOrder();
                                log.info("order is {0}" , $order);
                                setOrder($order);
                           }
                        
                
                        @Override
                        public List<E> getResultList()
                        {
                           if (getOpenFire()) {
                                return super.getResultList();
                           } else {
                                return null;
                           }
                        }
                        
                        @Override
                        public E getSingleResult()
                        {
                            if (getOpenFire()) {
                                 return super.getSingleResult();
                            } else {
                                 return null;
                            }
                        }
                        
                        @Override
                        public Long getResultCount()
                        {
                          if (getOpenFire()) {
                               return super.getResultCount();
                          } else {
                               return null;
                          }
                        }
                     public Boolean getOpenFire() {
                          return openFire == null ? false : openFire;
                     }
                     public void setOpenFire(Boolean openFire) {
                          this.openFire = openFire;
                     }
                
                
                     public ColumnOrder getColumnOrder() {
                          return columnOrder;
                     }
                
                     public void setColumnOrder(ColumnOrder columnOrder) {
                          this.columnOrder = columnOrder;
                     }
                     
                     
                }
                
                
                




                • 5. Re: Avoid loading all data from seam-gen default entity list...
                  Val Sw Expert
                  Thanks a lot Roger... I am going through your suggestion...

                  Main issue is when user clicks "ItemList" link from header, it fetches all records... I want to restrict... so that when  user clicks "ItemList" link from header entity query is not fired....

                  So, you are not using default list object generated by seam
                  @Name("itemList")
                  public class ItemList extends EntityQuery {
                  ....
                  }
                  It will be nice if you can send xhtml code where you are passing parameter...
                  ------------------------------------------------
                  You have to explicitily declare/send the parameter on the the menu, page descriptor, and each link/button tag that renders the view.
                  ------------------------------------------------
                  The link which user clicks is on the header menu (standard "menu.xhtml") how I can send parameter from here....
                  <s:link view="/ItemList.xhtml"
                             value="Search Item"
                  propagation="none" rendered="#{identity.loggedIn}"/>
                  • 6. Re: Avoid loading all data from seam-gen default entity list...
                    Roger Mori Newbie

                    Your list class must extend the aforementioned class HerlindaQuery plus :



                    Menu:


                    <s:link 
                       view="/relo/ReferralList.xhtml"
                       styleClass="image-command-link" 
                       propagation="none">
                       <f:param name="openFire"  value="#{false}" />
                    </s:link> 
                    
                    



                    Page descriptor


                    ReferralList.page.xml
                    .....
                    <param name="openFire" value="#{referralList.openFire}"/>
                    



                    Search Button or Link:


                    <h:form>
                    ....
                    <h:commandLink ....  >
                       <f:param name="openFire"  value="#{true}" />
                    </h:commandLink> 
                    .....
                    </h:form>
                    



                    • 7. Re: Avoid loading all data from seam-gen default entity list...
                      Val Sw Expert

                      Great...


                      Let me try I will get back....