A Peek Inside the Software Factory: Core Framework

If you ever wanted to modify ColdBricks or BugLog, but didn't understood how these application were constructed; or if you just want to see yet another way of developing CF applications, then this post may be for you.

I just posted some pages describing the framework I use for developing CF projects. It doesn't even has a proper name, I just call it "Core" due to its simplicity and its minimalistic nature. The basic principle of this framework, and the reason why I choose to use it instead of going with more traditional offerings, is that it only focuses on one thing and one thing only: provide a formal mechanism for going from one page to another and for invoking actions.

It doesn't do any fancy things, no complex request lifecycles, no sophisticated caching, no extensive API, none; however, it does provide enough extension points to which I can hook any functionality that I desire on a per-project basis. Basically the framework consists on a Front Controller implementation, a base event handler and a few conventions for directory structure and nomenclature.

Anyway, you can find the code and read more about this framework by going to the Projects section or by going directly here.

Using HomePortals and ColdBox Together

This afternoon I have been experimenting with a somewhat interesting and funky idea: mixing the layout rendering engine of HomePortals with a full application framework like ColdBox.

Why? Because integrating these two engines would allow developers to create applications that can benefit from the modularity provided by HomePortals on the front end and at the same time enjoy all the swiss-army knife functionality provided by ColdBox, in particular the rich control over the lifecycle of the requests and the application.

For example, this could be great for developing dashboards or BI applications. HomePortals would make it easy to create a modular interface based on small widgets or pods, and ColdBox could handle the overall application structure and tasks (security, persistence, logging, etc).

In theory it sounded possible, so I just went ahead and see what I could get. Well, at the end I found that the two worked beautifully together.

I do not have yet a full working application that I can share, so for the time being this is just "proof-of-concept" type of stuff.

Here is what I did.

** For this I used ColdBox 2.5.2 and HomePortals 3.0.189, which are the current releases for both projects.

First I created a new coldbox application using the "ApplicationTemplate" found on the standard ColdBox distro. I named the new application "hpcoldbox" and put it on a directory under my web root so I could get to it by going to: http://localhost/hpcoldbox

The first part was setting up the HomePortals side, which was basically just modifying the newly created application to look like a HomePortals site and then writing a sample page to display. Let me describe this step by step.

Within the "config" directory I added the two main HomePortals configuration files: homePortals-config.xml and accounts-config.xml.cfm

homePortals-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<homePortals>
   <appRoot>/hpcoldbox/</appRoot>
   <accountsRoot>/hpcoldbox/accounts/</accountsRoot>
</homePortals>

accounts-config.xml.cfm

<?xml version="1.0" encoding="UTF-8"?>
<homePortalsAccounts version="1.0">

   <!-- Root directory for account directories -->
   <accountsRoot>/hpcoldbox/accounts/</accountsRoot>

   <!-- storage type -->
   <storageType>xml</storageType>
   <storageFileHREF>/hpcoldbox/accounts/accounts.xml</storageFileHREF>

</homePortalsAccounts>

Those files provide a very basic configuration for HomePortals. The first one just states where the application is located and where will the account files be stored. The second one just expands a bit on some details about how we are going to store the account data.

Next I needed to create an account an a sample page. For that, under the root of the new application, I created a new directory named "accounts", with the following internal structure:

To make things easier I just copied the accounts.xml and site.xml from /Home/Accounts/accounts.xml and /Home/Accounts/default/site.xml since I was using pretty much a default setup.

For default.xml, which is our sample page, I used the following code:

<?xml version="1.0" encoding="UTF-8"?>
<Page access="general" owner="default">
   <title>HP+ColdBox</title>
   <stylesheet href="/Home/resourceLibrary/Pagetemplates/layouts/layoutTemplates.css"/>
   <skin id="boxy"/>
   <layout>
      <location class="column_small" id="h_location_column_2" name="left" type="column"/>
      <location class="column" id="h_location_column_3" name="middle" type="column"/>
      <location class="column_small" id="h_location_column_4" name="right" type="column"/>
   </layout>
   <modules>
      <module displayMode="short" id="rssReader1" location="left" maxItems="10" name="RSSReader/RSSReader"
            rss="http://www.coldfusionbloggers.org/rss.cfm" />

      <module id="FlickrFeed1" location="middle" maxItems="10" name="flickrFeed/flickrFeed"
            onClickGotoFlickr="true" showheader="true" tags="coldfusion" title="FlickrFeed1"/>

      <module displayMode="short" id="rssReader2" location="right" maxItems="10" name="RSSReader/RSSReader"
            rss="http://digg.com/rss/index.xml" title="Digg"/>

   </modules>
</Page>

Nothing fancy, just display a couple of feeds and a flicker photo stream.

Finally I had to create a template to allow HomePortals modules to talk back to HomePortals in an asynchronous way. So I created a file named gateway.cfm in the root of the application with the following contents:

<cfinclude template="/Home/Common/Templates/gateway.cfm">

That was it for the HomePortals side. The next part was doing the ColdBox part.

HomePortals works basically as an API, that means that everything is object-based, so the crucial part is to have an instance of the HomePortals main object, which is Home.components.homePortals. The best practice is to instantiate it as a singleton and just leave it on the application scope. Since we need to do this only once for the lifetime of the application, I added the following code to /hpcoldbox/handlers/main.cfc

<cffunction name="onAppInit" access="public" returntype="void" output="false">
   <cfargument name="Event" type="coldbox.system.beans.requestContext">
   <!--- ON Application Start Here --->
   <cfset application.homePortals = createObject("component","Home.components.homePortals").init("/hpcoldbox/")>
</cffunction>

I know ColdBox offers more options for these kind of things but for the purpose of the experiment this seemed like the quickest way to get up and running.

Then, I modified the default event (general.dspHome) in /hpcoldbox/handlers/general.cfc

<cfcomponent name="general" extends="coldbox.system.eventhandler" output="false">
   <cfsetting enablecfoutputonly="false">

   <cffunction name="dspHome" access="public" returntype="void" output="false">
      <cfargument name="Event" type="coldbox.system.beans.requestContext">
   
      <cfset var account = "default">
      <cfset var page = "default">

      <cfset var oPageRenderer = application.homePortals.loadPage(account, page)>
      <cfset var html = oPageRenderer.renderPage()>
   
      <cfset Event.setValue("html", html)>   
   
      <!--- Set the View To Display, after Logic --->
      <cfset Event.setView("home")>
   </cffunction>
</cfcomponent>

What this code does is get the homePortals instance and load the page named "default" on the account named "default". After the page has been loaded and parsed internally, it then asks for the rendered HTML corresponding to that page. Then we set that returned html content into a variable named "html" in the request collection. Finally we set the view to render.

Notice also the <cfsetting> tag that I had to add on top. This was needed because it seems that coldbox internally has it set to true and that affected the rendering of some parts of the output in HomePortals.

Next I modified the default layout file (/hpcoldbox/layouts/Layout.Main.cfm) to just limit itself to render the view. I did this because the output of the HomePortals rendering is already a full HTML document. However, you can modify your HomePortals settings to only a partial HTML page and use ColdBox layouts to handle the page's HTML structure.

This is what my Layout.Main.cfm looked like:

<cfoutput>#renderView()#</cfoutput>

The last piece was updating the view (views/home.cfm) in the same way.

<cfset html = Event.getValue("html")>
<cfoutput>#html#</cfoutput>

And that was it, when I went into my browser and fired up the application, the HomePortals page was rendered perfectly.

Again, this is a very simple proof-of-concept but I trust that if you are familiar with ColdBox you can see how this fully integrates into the application. You could have some pages rendered normally and some pages rendered with HomePortals; and thats without even going into further integration within custom HomePortals modules that you could write that could take advantage of the coldboxproxy to make even more interesting things.

I am really excited to have been able to find this out, as I said at the beginning, because I think it opens the door to very interesting opportunities. It would also be interesting to see if HomePortals can also be integrated in the same manner with Model-Glue, MachI, Fusebox, or other full application frameworks; however my practical knowledge of those is even less than what I know about ColdBox, so if anyone is willing to give it a try I'd love to hear how it went.

Thats it for now,

Happy coding!

A Rant on Frameworks, Libraries, and Shells

We spend ridiculous amount of time discussing the merits (or lack of) of the different MVC frameworks in ColdFusion, and we keep doing it again and again. Well, at least everyone should agree that when it comes time to decide how to go from one page to another we got that pretty much well covered. But for all the OO fever taking over the hard-core ColdFusion community as of lately, why are we still focusing on the presentation layer still, which honestly is the least OO place in the whole application? Where are the repositories of just plain libraries? components and subsystems that we plug together to provide sophisticated functionality to our applications regardless of how the presentation layer is done.

Yes, we have Transfer, ColdSpring, and Reactor, and they really rock; but it seems that that's where the list ends. Has nobody written a really tight, super strong, caching library? what about a job-scheduling library? It could be that the lack of these libraries as separate entities is what motivates MVC framework authors to add more and more complexity to their projects, which in turn fuels the discussions of why these frameworks are so bloated and complicated. I know Luis, from ColdBox, has put a lot of effort in building the caching functionality in his framework, and knowing the quality of his code I'm pretty sure it kicks a$$; but sadly is all tied into the framework. Wouldn't it be much more beneficial to everyone if there were already some project out there that would provide this functionality so that you could just plug it in into your application?

If we have enough of these little libraries that would focus on doing one thing and one thing only, then the 'framework' in which an application is built would not need to be these gigantic-swiss-army-knife platforms that we are getting used to. They would become lighter and lighter until they are reduced to a 'core', just down to the basic principle that embodies their core ideas. Imagine a coldbox-core, a modelglue-core, a fusebox-core, super small code bases that just provide the basic guidelines and minimal code to support a proposal on how an application should be structured; And then on top of them we could have 'distributions' or 'shells', canned projects that would group together a 'core' and a few libraries to put together a basic solution, custom tailored for specific purposes. For example, you could have a shell for an intranet application that includes the framework core, a caching subsytem, a security subsystem, an IOC subsystem and an ORM subsystem; or on the other hand there could be a shell for a plain website that may only include the framework core and a caching subsystem. The bottom line is that all those parts can be plugged in an out and replaced or extended, and the application as a whole could be customized to the specific needs and would not need to carry any added complexity that is not desired by the author.

If I may give a suggestion, we should move on from the MVC frameworks and start focusing in these kind of projects. We need to focus more on libraries and subsystems in that the only interface is an API that can be used by other applications. Of course, in order to do that, it should be easy for everyone to find these libraries. RIAForge makes a terrific job as a repository of entire projects, and maybe it could be extended to add a new category exclusively for ColdFusion libraries and APIs; or maybe we need an entirely new website to allow us to post and search libraries for different types of functionalities that anyone wanted to add to their application.

Any thoughts?

ColdBricks Update and Documentation

New updated versions of ColdBricks and HomePortals are now available for download.

ColdBricks 1.0.377:

- Fixed issues with case-sensitive OSes

- Fixed compatibility issues with BlueDragon

- Added option to edit current skin from the Page Editor screen

- Added option to create a Skin resource based on a page's local stylesheet

- Fixed minor bugs

HomePortals 3.0.189:

- Added support for BlueDragon and OpenBlueDragon

- Added support for case-sensitive operating systems

Also, the ColdBricks User's Guide is now finished and ready for download.

You can download the new ColdBricks release and the user's guide from the Downloads area in the ColdBricks site.

If you want to get the new HomePortals release by itself, you can get it from the HomePortals site.

Enjoy!

ColdBricks 1.0

So it's official, my new venture is now live and open to the public. ColdBricks is a free and open source content management system specially tailored for highly modular websites like portals and dashboards. The current version runs on ColdFusion 7, 8 and Railo 2 (still having problems with BlueDragon though).

[More]

HomePortals 3 Portal Framework

Well, after several years of going back and forth with this project, I finally decided to share it with everyone and release my little baby as an open source project. HomePortals is a framework or platform for creating and running portals in ColdFusion. Most of the features in HomePortals focus around modularity, reusability of visual components, and personalization.

Besides providing the framework, conventions and APIs for creating the sites, HomePortals also acts as a 'runtime' or 'rendering' engine. All pages in a HomePortals application are actually XML documents that describe the elements and modules to display as well as their layout and arrangement. The HomePortals engine is responsible for reading, parsing and rendering the actual pages based on the specifications of the given XML documents. This is a little bit like MXML in Flex, but in ColdFusion.

I have succesfully tested HomePortals in ColdFusion MX 7, ColdFusion 8 and Railo 2. I have not yet had the chance to try it out in BlueDragon.

I created a small site for this project, where you can download the framework, a sample application and find some documentation. The URL for the site is http://www.homeportals.net

HomePortals has an LGPL license, which means that the library itself has to remain open source and any changes have to be shared, but it can also be used by non open source applications as an external library or component of the application.

If someone wants to try HomePortals out I'd really like to hear some feedback.

Another related project I will be releasing soon is ColdBricks... but I'll talk about that some other time :)

BlogCFC was created by Raymond Camden. This blog is running version 5.9. Contact Blog Owner