By Peter Bell

Snippets: Displaying an Iterating Object

In my last post, I described how to build an iterating business object to get all of the benefits I've been touting for a while. In this post, I look at how to use such an object to display the information in a view or a list . . .

Lets say we wanted to display a simple list of users, displaying FirstName, LastName and Age in a table. The code in the view would be as follows:

<table>
<tr>
   <td>First Name</td>
   <td>Last Name</td>
   <td>Age</td>
</tr>
<cfset Product.first()>
<cfloop condition="NOT #Product.isLast()#">
   <tr>
   <td>#Product.get("FirstName")# </td>
   <td>#Product.get("LastName")# </td>
   <td>#Product.get("Age")# </td>
   </tr>
   <cfset Product.next()>
</cfloop>
</tr>
</table>

That's it!!! Of course, this raises a bunch of questions about how the generic getters shoould work in a way that won't be buggy - or evil. But that is the topic of another post. Stay tuned!!!

Comments
BlogCFC was created by Raymond Camden. This blog is running version 5.005.