« Return to Thread: Iterating Over a Collection on Html

Re: Iterating Over a Collection on Html

by Joshua Hansen :: Rate this Message:

Reply to Author | View in Thread


Hi Rahul,

I'm not sure that the setBean() method automatically populates lists, so
you'll need to do that manually.  Keep in mind that classes can have
properties with the same names, so using the setBean() method which
accepts a prefix is a good idea.

-[Bean outlines]--------------------------------
public class Hotel {
        public String getName() ...
        public void setName(String name) ...

        public List<Room> getRooms() ...
        public void setRooms(List<Room> rooms) ...
}

public class Room {
        public int getNumber() ...
        public void setNumber(int number) ...
}


-[Sample template]-----------------------------
<r:v name="hotels"/>

<r:b name="hotel">
   Hotel Name: <r:v name="HOTEL:name" /><br />
<r:v name="rooms" />
</r:b>

<r:b name="room">
   Room Number: <r:v name="ROOM:number" /><br />
</r:b>

-[Sample element snippet]----------------------
        ...
        for( Hotel hotel : hotels ) {
                template.setBean(hotel, "HOTEL:");

                template.blankValue("rooms");
                for( Room room : hotel.getRooms() ) {
                        template.setBean(room, "ROOM:");
                        template.appendBlock("rooms", "room");
                }
                template.appendBlock("hotels", "hotel");
        }
        ...
-----------------------

Josh
--
Joshua Hansen
Up Bear Enterprises
(541) 760-7685


Rahul wrote:

> I have a bean object(a Hotel object) which contains a List (rooms for
> this hotel object).
> I am setting the Hotel bean to the template like this
>
>   template.setBean(hotels);
>
>   and
>
>   template.appendBlock("hotels", "hotel");
>
>   to access the bean on the template.
>
>  However I am not able to iterate over the List object on the
> template. How can I do this.
>
>  Any help will be appreciated.
>
> Thanks in advance.
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "rife-users" group.
To post to this group, send email to rife-users@...
To unsubscribe from this group, send email to rife-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rife-users?hl=en
-~----------~----~----~----~------~----~------~--~---

 « Return to Thread: Iterating Over a Collection on Html

 
 
 
Google
rifers.org web