Neptune 1.0 Beta 3 Documentation: Custom Display

Neptune Information

Download from RIA Forge

Custom Display

The "Getting Started" section covers how to create an administrative interface for your data, but that will hardly be sufficient. You need to be able to display the data elsewhere as well.

Fortunately this will be very much like in any vanilla ColdFusion application (except, hopefully, a bit easier). We will do a very brief example of outputting information from the Contact-O-Matic program created in the "Getting Started" section.

Here is a page to output all of the contacts from Contact-O-Matic:

<cfset qContacts = Application.ContactOMatic.Contacts.getContacts()>

<cf_Template
	title="Contacts"
	showTitle="true"
>

<table border="1" cellpadding="3" cellspacing="0">
<tr>
	<th>&nbsp;</th>
	<th>Name</th>
	<th>Type</th>
</tr>
<cfoutput query="qContacts">
<tr>
	<td><cfif Len(ContactThumbnailURL)><img src="#ContactThumbnailURL#" alt=""></cfif></td>
	<td>#ContactName#</td>
	<td>#ContactType#</td>
</tr>
</cfoutput>
</table>
<ul>
</ul>

</cf_Template>

The point here isn't the specific output of the page, but rather that you can simply use a query any way you want in order to output your data. You could also use a Page Controller if you wanted to be more proper, but that is often overkill when you only have one line of code to retrieve data from the model. It is easy to create a page controller for the page later if the model interaction gets more complicated.

With a Page Controller

The correct way to handle the above example would actually be to use a page controller to handle the interaction between the view and the model. Often with only one line connecting the two, direct interaction is acceptable but anything more complicated warrants a page controller. Here is the above example with a page controller:

Page Controller

<cfcomponent extends="_config.PageController" output="no">

<cfset loadExternalVars("Contacts",".ContactOMatic")>

<cffunction name="loadData" access="public" returntype="struct" output="no">
	
	<cfset var vars = StructNew()>
	
	<cfset vars.qContacts = variables.Contacts.getContacts()>
	
	<cfreturn vars>
</cffunction>

</cfcomponent>

View File

<cf_PageController>

<cf_Template
	title="Contacts"
	showTitle="true"
>

<table border="1" cellpadding="3" cellspacing="0">
<tr>
	<th>&nbsp;</th>
	<th>Name</th>
	<th>Type</th>
</tr>
<cfoutput query="qContacts">
<tr>
	<td><cfif Len(ContactThumbnailURL)><img src="#ContactThumbnailURL#" alt=""></cfif></td>
	<td>#ContactName#</td>
	<td>#ContactType#</td>
</tr>
</cfoutput>
</table>
<ul>
</ul>

</cf_Template>

Next: Unit Tests