3 Replies Latest reply on Nov 25, 2007 8:02 AM by arussel

    Getting outjected object's attributes

    ferd0

      This is a siplified problem of mine. I would like to see, if I am doing anything conceptually wrog.

      This is my object (simplified):

      Hotel
       int nrOfStars;
       @OneToMany
       List<Room> rooms;


      I outject an instance of this object (or I use it in statefull session bean), and I try to show it's attributes in xhtml.

      But I can display hotel's nubmer of stars, but I can not access list of rooms, although they are present (in database). I add rooms with "hotel.getRooms().add(room)".

      I see correct output of
      <h:outputText value="#{hotel.nrOfStars}" />
      , but I can't see proprely
      <h:outputText value="#{fn:length(hotel.rooms)}" />
      (I get always "0").

      How can I access a list of objects in my outjected object? It works if I outject the list itself, but not if i try to access the list "in outjected parent object".
      I hope I've explained the problem properly.

      Ferd0

        • 1. Re: Getting outjected object's attributes
          arussel

          are you looking for: #{hotel.rooms.size()} ?
          (using jboss el)
          alex

          • 2. Re: Getting outjected object's attributes
            ferd0

            Actually, I would like to do something like this:

            <h:dataTable value="#{hotel.rooms}" var="room">
             <h:column>
             <h:outputText value="#{room.number}" />
             </h:column>
            </h:dataTable>

            but it is not working.

            The problem is, that if I would outject list "rooms", and use
            <h:dataTable value="#{rooms}" var="room">
            it would work, but the version with "hotel.rooms" is not working.

            I don't know if I'm using JBoss EL (I am using templates generated by seam-gen).

            My environment: JBoss AS 4.0.5, JBoss Seam 1.2.1.

            • 3. Re: Getting outjected object's attributes
              arussel

              This defenitly works:

              <h:dataTable value="#{hotel.rooms}" var="room">
               <h:column>
               <h:outputText value="#{room.number}" />
               </h:column>
              </h:dataTable>
              


              If it is not working then you have a typo somewhere.
              1. first check your getter/setter for rooms.
              2. output #{hotel.rooms} to see if you got a list
              3. use a datable as you did and just output #{room}

              alex