3 Replies Latest reply on May 29, 2008 10:41 AM by nickarls

    data table

    antonio

      Hallo,


      I have this problem:


      I want to show results of a query hql using 2 entities .
      I want to show results in a facelet using tag


      <h:dataTable id="list" value="#{list}" var="list_elem" >


      Where list is obtained from a session bean.
      I found many examples whith only one entity bean .


      Where can I find an example with 2 or more entity bean?



      Tanks for eny advice

        • 1. Re: data table
          nickarls

          Hmmm, you could try wrap them in some object like


            public class Wrapper {
              AObject a;
              BObject b;
            }
          
            and
          
            public List<Wrapper> getData() ...
          
            and
          
            <h:outputText value="list_elem.a.aproperty"/>
          



          • 2. Re: data table
            antonio

            Thanks for your post,but your answer is so criptic.
            I must admit my answer wasn't clear.
            I'll try to reformulate my problem:


            I have 2 entity beans like follows:



            @Entity
            @Name("a")
            public class A {
            @Id
            private String x;
            private String y;
            ...getters,setters and constructors here
            
            }



            @Entity
            @Name("b")
            public class B {
            @Id
            private String x;
            private String z;
            ...getters,setters and constructors here
            
            }



            I want to obtain a list of couples of objects A a and B b with


            a.x=b.x




            and show this list in my facelet.
            With only A entity I can do this way:



            @Stateful
            @Name("aAction")
            @Scope(ScopeType.SESSION)
            public class A_Action{
            @DataModel
            List<A> la;
            @PersistenceContext
            private EntityManager em;
            public void query(){
            la=em.createQuery("select a from A a").getResultList();
            }
            
            }



            In this way with method query I can instanciate la and show results.
            I want to do same whith the 2 entities above.


            Tanks

            • 3. Re: data table
              nickarls

              Guessing here but the query


              
              select a,b from A a, B b where a.x = b.x
              
              



              Should return a Object[2]


              But that's not really a join(?)