3 Replies Latest reply on May 24, 2010 2:00 PM by anitha.nagani.raj.gmail.com

    How to make a custom search using seam components?

    oussama

      I’m developing an application using as framework JBoss Seam and I encountered a problem that I couldn’t solve since a week. I hope I can find a solution in this group.
      First, I was using the totoList.xhtml, totoList.java session and the toto entity as it is generated by Seam-Gen. But, this could work only for a classic list search that means when the attributes are those present in the entity. This allows me to search for any attribute using toto.attribute in the inputText normally when the type is a string or to be modified for other types like int.
      But, my situation is more complicated:
      This is the first entity: Demande



      |@Entity
      @Table(name = "DEMANDE", schema = "SIMM_SYS")
      @javax.persistence.SequenceGenerator(name = "SEQ_DEMANDE", sequenceName = "SEQ_DEMANDE", allocationSize = 1)
      public class Demande implements java.io.Serializable {
      
              private int id;
              private Navire navire;  
              private String nomdemandeur;
              private String prenomdemandeur;
              …
      @ManyToOne(fetch = FetchType.LAZY)
              @JoinColumn(name = "REFNAVIRE")
              public Navire getNavire() {
                      return this.navire;
              }
      
              public void setNavire(Navire navire) {
                      this.navire = navire;
              }
      …
      }|




      This is the second entity: Navire



      @Entity
      @Table(name = "NAVIRE", schema = "SIMM_SYS")
      @javax.persistence.SequenceGenerator(name = "SEQ_NAVIRE", sequenceName = "SEQ_NAVIRE", allocationSize = 1)
      public class Navire implements java.io.Serializable {
      
              private int id;
              private String matricule;
      …
      @OneToMany(fetch = FetchType.LAZY, mappedBy = "navire")
              public List<Demande> getDemandes() {
                      return demandes;
      }
      …
      }




      In the demandeList.xhtml page it works only when I use it for the classic one (same thing for the navireList.xhtml).
      The problem start when I wanted to make a search for an attribute from the navire entity in the demandeList.xhtml (or from the demande entity in the navireList.xhyml) in order to get a search for attributes that exit in the two entities.
      Example: when I made a search for the attribute navire.matricule in the demandeList.xhtml like this:



      <s:decorate template="layout/display.xhtml">
      <ui:define name="label">N° Enregistrement</ui:define>
      <h:inputText id="idSearch" value="#{demandeList.demande.navire.matricule}">
                      </h:inputText>
      </s:decorate>




      And I added the parameter in the page demandeList.page.xml:



      <param name="demande.navire.id" value="#{demandeList.demande.navire.id}"/>  




      And I added this line in the demandeList.java session as a restriction:


      "demande.navire.id = #{demandeList.demande.navire.id}",




      I received this error:


      Exception during request processing:
      Caused by javax.servlet.ServletException with message: "/DemandeList.xhtml @43,73 value="#{demandeList.demande.navire.id}": Target Unreachable, 'navire' returned null on
      …entities.demande

      Caused by javax.el.PropertyNotFoundException with message: "/DemandeList.xhtml @43,73 value="#{demandeList.demande.navire.id}": Target Unreachable, 'navire' returned null on the …entities.demande


      I hope I can find a solution. Thanks a lot.

        • 1. Re: How to make a custom search using seam components?
          lvdberg

          The restriction can only result in a null, because the thing you doing now is to navigate the object-tree from a collection to a single entity, to another entity, to an attribute.


          That works with many-to-one, or a reference to a single object in the collection (with an index), but not by referencing the whole collection.




          • 2. Re: How to make a custom search using seam components?
            oussama

            I tried to make the search for the value demandeList.demande.navire.id in the demandeList.xhtml page and for the value navireList.navire.demande.id in the navireList.xhtml page and I come out with the same error target unreachable.


            In the case of demandeList.demande.navire.id I'm using the many-to-one and as I said it doesn't work.


            Thank you for your response.

            • 3. Re: How to make a custom search using seam components?
              anitha.nagani.raj.gmail.com
              HI,

              I'm new to seam and i'm facing a similar kind of issue. I have two tables Site and Location. Site ia at a higher level. Both the tables are related. site id is being used as a foreign key in location table. Now i want to have  location name as a field in the Site search filter. While searching, if the user enters the location name then the site associated with the entered location should be displayed else it should display all sites.

              This is my site.java
              @Entity
              @Table(name = "site", catalog = "custinfodb")

              public class Site implements java.io.Serializable {
              private Set<Location> locations = new HashSet<Location>(0);

              @OneToMany(fetch = FetchType.LAZY, mappedBy = "site")
                   public Set<Location> getLocations() {
                        return this.locations;
                   }

                   public void setLocations(Set<Location> locations) {
                        this.locations = locations;
                   }
              }


              How should i write the query inorder to accomplish this task? Please explain me in detail