1 Reply Latest reply on Jun 16, 2010 9:53 AM by Umut Fikret Gürkavcu

    How to iterate through the collection

    Anitha Raj Newbie
      Hello all,

      Anyone please let me know how to deference a collection in seam? Let me explain me scenario.
      I have two tables Site and Contract with one to many relationship between them. Site is at a higher level therefore Contract is stored as a collection in site.java POJO class.

      Site.java:
      public class Site implements java.io.Serializable {

      private List<Contract> contracts = new ArrayList<Contract>(0);

      @OneToMany(fetch = FetchType.LAZY, mappedBy = "site")
           
           public List<Contract> getContracts() {
                return this.contracts;
           }

           public void setContracts(List<Contract> contracts) {
                this.contracts = contracts;
           }

      List Contract has Contract Number as a property. Now i want to have contract number as a search criteria in site search page.

      I have added a restriction in SiteList.java page as follows.

      "lower(site.contracts) like concat(lower(#{siteList.contracts}),'%')"

      In siteList.xhtml i'm passing the value as follows.

                  <s:decorate template="layout/display.xhtml">
                  <ui:define name="label">Contract No</ui:define>
                  <h:selectOneMenu value="#{siteList.site.contracts}">
                  <s:selectItems  value="#{contractList.resultList}" var="_d" label="#{_d.contractNo}" itemValue="#{_d.contractId}" noSelectionLabel="Select"></s:selectItems>
                         </h:selectOneMenu>
                  </s:decorate>

      How should i iterate through the collection and make the search work?
            
        • 1. Re: How to iterate through the collection
          Umut Fikret  Gürkavcu Newbie


          List<Object> resultList=getResultList();
               
          for (Iterator iterator = resultList.iterator(); iterator.hasNext();) {
                         
                         // Fetching the row value               
                          Object[] o = (Object[]) iterator.next();
                          
          
                         // Reach the fields like 
                                 List<Contract> contractList=(List<Contract>) o[index of field];
          
                    
          }