Iterating Over a Collection on Html

1 view
Skip to first unread message

Rahul

unread,
May 5, 2009, 4:03:07 AM5/5/09
to rife-users
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.

Josh Hansen

unread,
May 5, 2009, 11:03:22 AM5/5/09
to rife-...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages