Extending Fusebox's Coldspring Lexicon

Technical , Framework , AJAX , fusebox , coldspring Add comments

Tonight I flexed some brain matter and delved into some previously-uncharted realms of modern Fuseboxing and Coldspring. To understand where I'm coming from, keep in mind that only a year and a half ago I was a Fusebox 3.0 guy and even today about 90% of our existing applications are still running on that version. Where Coldspring is concerned, I haven't yet found the time to test the waters with that enough to see it into a production application. This evening has made some great progress on that particular front, however.

The Coldspring Integration Into Fusebox

I'm building a simple user manager tool, which is powered by ExtJS (if you're following my journies you may have noticed that I'm fond of ExtJS lately). Taking the serious leap into Coldspring for the first time, I downloaded and installed the custom Fusebox lexicon for Coldspring and found enough documentation and examples to get that running. I added this to my fusebox.xml:

Please bear with me, I'm still working on the Mango Blog code output.ᅠ :(

<globalfuseactions>
<appinit>
<fuseaction action="core.coldSpringSetup" />
</appinit>
<preprocess></preprocess>
<postprocess></postprocess>
</globalfuseactions>

The coldSpringSetup fuseaction performs the following actions:

<fuseaction name="coldSpringSetup">
<cs:initialize coldspringfactory="servicefactory" useexisting="true" defaultproperties="#StructNew()#">
<cs:bean beanDefinitionFile="#ExpandPath('/coldspring.xml')#" />
</cs:initialize>
</fuseaction>

That takes care of all the bean loading as far as the Fusebox framework is concerned. Now this was working great so far; I was really digging on it. The login piece to the application was retrieving the user object from the service factory and performing the authentication without a hitch.

A Wrench in the Gear: AJAX

Here's where the problem comes in. Right past the login screen is the one stable piece of the application I've built so far, which happens to be (conveniently) managing users. An editable grid is loaded up and immediately calls out on-page-load to a service.cfc that returns a collection of User objects in JSON. It quickly dawned on me that it would be a good practice to use Coldspring from the service component just as I am doing in the Fusebox. While we're wearing our "good practices hat" let us also state that since we're already using the bean factory in the application framework it would be silly not to use the same one we instantiated over in the component. Otherwise, we'll have two factories in memory and that's just plain waste.

Here's where I ran into trouble. The lexicon inside Fusebox sets up the factory inside the myFusebox application data cache. This is not available to the service component sitting out there receiving AJAX calls. What's a developer to do? Let me show you where the lexicon puts the factory:

myFusebox.getApplication().getApplicationData().servicefactory = createObject("component", "coldspring.beans.DefaultXmlBeanFactory").init();

As you can see that's going to be handy for Fusebox but not for the service component. I emailed into the Fusebox mailing list to see what kind of advice I could scrape up. Barney Boisvert was the only person posting at my late hour, and he was very helpful. Basically there is no shortcut to get what I wanted. Some modification to the lexicon was going to be necessary if I was going to re-use an existing Coldspring bean factory in the Fusebox framework that had already been instantiated in a scope available to my service component as well.

New Lexicon Attribute

What I have so far, and it's working on my development server, is a mutation of initialize.cfm (from the Coldspring lexicon) that contains an optional boolean parameter "useexisting". In my situation I was already feeding it the "coldspringfactory" attribute with a value of "servicefactory". My thinking here was that if I wanted it to keep doing what it always had done before I started meddling, it wouldn't do to pass in a scoped variable name for this value, such as "application.servicefactory". I wanted to try to keep the operation of this parameter untouched.

So what I did instead is check to see if "useexisting" is true, and if so take a tour through the three main persistent scopes in a narrow-to-widest order: session, application, and server. In each one look for the variable with the name passed in through the "coldspringfactory" attribute, which in my case was "servicefactory". Here's what some of that checking code looks like:

// check to see if the user has requested that we re-use an existing copy of the bean factory in a persistent scope
if (fb_.useexisting) {
fb_.arPersistentScopes = arrayNew(1);
// We'll go in order of narrowest to greatest scope

arrayAppend(fb_.arPersistentScopes, "session");
arrayAppend(fb_.arPersistentScopes, "application");
arrayAppend(fb_.arPersistentScopes, "server");
fb_.blnFoundBeanFactory = false;

for (i = 1; i lt arrayLen(fb_.arPersistentScopes); i++) {
if (structKeyExists(evaluate(fb_.arPersistentScopes[i]), fb_.coldspringfactory)) {
// Now check its meta data to make sure this is really a Coldspring bean factory

fb_.stMeta = getMetaData(evaluate("#fb_.arPersistentScopes[i]#.#fb_.coldspringfactory#"));
if (fb_.stMeta.name eq "coldspring.beans.DefaultXmlBeanFactory") {
fb_.blnFoundBeanFactory = true;
fb_.sServiceFactoryInit = "#fb_.arPersistentScopes[i]#.#fb_.coldspringfactory#";
break;
}
}
}

if (not fb_.blnFoundBeanFactory) {
// User wanted to re-use something, but we couldn't find a valid object

// Standard bean factory creation, like it always was

fb_.sServiceFactoryInit = 'createObject("component", "coldspring.beans.DefaultXmlBeanFactory").init(defaultProperties="#fb_.defaultproperties#" )';
}
ᅠᅠᅠ ᅠᅠᅠ }
ᅠᅠᅠ ᅠᅠᅠ else {
ᅠᅠᅠ ᅠᅠᅠ ᅠᅠᅠ // The user does not wish to re-use a Coldspring bean factory
ᅠᅠᅠ ᅠᅠᅠ ᅠᅠᅠ // Standard bean factory creation, like it always was.
ᅠᅠᅠ ᅠᅠᅠ ᅠᅠᅠ fb_.sServiceFactoryInit = 'createObject("component", "coldspring.beans.DefaultXmlBeanFactory").init(defaultProperties="#fb_.defaultproperties#" )';
ᅠᅠᅠ ᅠᅠᅠ }
ᅠᅠᅠ ᅠᅠᅠ // set ColdSpring in this fusebox instance's application space
ᅠᅠᅠ ᅠᅠᅠ fb_appendLine('<cfset myFusebox.getApplication().getApplicationData().#fb_.coldspringfactory# = #fb_.sServiceFactoryInit# />');

Not quite finished yet

Barney pointed out on the mailing list, pretty much after I had coded the majority of all this, that it could indeed be troublesome for the lexicon's initialization code to go poking around through various scopes. A dead-certain and straight-forward command telling the lexicon where to find the factory might just be cleaner, and in retrospect I have to agree. I'll see how this can be done, perhaps another day. When I've got the full solution, I'll send it in to the FB mailing list and maybe it will become something we can all use. Let me know if you have any suggestions, I'm all ears!

16 responses to “Extending Fusebox's Coldspring Lexicon”

  1. Brian Rinaldi Says:
    I have a note on managing code blocks in my post about moving to Mango that might solve your problems.

    http://www.remotesynthesis.com/post.cfm/making-the-move-to-mango
  2. Adam Bellas Says:
    @Brian, thanks for the input. I found that post of yours in a Google search of desperation the other night. I think after the wrestling with Coldspring and Fusebox I was too tired to experiment. I just finished implementing your tweak for the postForm.cfm. Looks better now, but geez I wish white space was honored, as in a PRE tag. So much for indenting. I'm sure there's a way to get it working. There are so many sweet code-display widgets out there, I want a nice one too!

    One thing that's a downer is that if I try to go back and edit the post after adding the code via your tinyMCE tweak, it's been filtered out! I need to go to the DB to retrieve it, or copy it from the blog post page. This just isn't satisfactory...
  3. Anthony Patch Says:
    I was wondering how to bind to a cfc that has been invoked via fusebox coldspring in a cfgrid tag. Any ideas?
  4. Adam Bellas Says:
    @Anthony, we had a good discussion about this on the Fusebox mailing list. The general consensus was that the default approach that the CS lexicon in FB uses does not offer a way to access it via remoting / ajax calls.

    The best approach does in fact seem to be instantiating it ahead of time in a shared scope (I think application works best) and using that from FB. If you want to avoid generating another bean factory, you can do like I did and enhance the lexicon to have the factory pointed to.

    Does that answer your question?
  5. ugg boots sale Says:
    so good.genuine <a href="www.vipuggstores.com/">ugg boots</a> range for 2010.many ugg boots at great prices.huge range,all with fast.
  6. Chi Hair Straightener on sale Says:
    so nice .online <a href="www.chiflatiron4u.com/">chi hair iron</a> shop provide kinds of chi stylers.chi purple hair straightener.
  7. GHD hair straightener Says:
    well,nice post.whatever your hair tpye is,<a href="www.topghdmart.com/">ghd hair straightener</a> protects your hair while styling.enjoy the free shipping.
  8. nhlbuy Says:
    <body>
    There are different types of straightening iron hair stylers available out there in the market for sale<a href="http://www.ghdhaironstyler.com/dark-ghd-iv-styler-p-13178.html?cPath=482">; ghd iv dark styler</a>. Those available in the GHD range are unquestionably <a href="http://www.ghdhaironstyler.com/chi-blue-camo-ceramic-flat-iron-p-13172.html?cPath=476">ghd purple styling set</a> the best hair straighteners. They have emerged as the staple of the beauty market because of the tremendous features and amazing results that they have to offer<a href="http://www.ghdhaironstyler.com/chi-camo-green-ceramic-flat-iron-p-13174.html?cPath=478">; ghd hot pink styler</a>. The best thing about them is that they are not only easy to use, but they are also incredibly reliable. Unlike other models, they rarely fail. They can straighten your hair in a significantly lesser time because they work at quite a hot level. <a href="http://www.ghdhaironstyler.com/chi-pink-ceramic-flat-iron-p-13176.html?cPath=480">chi flat iron </a> Interestingly, they also cool down very quickly. Quick heat up<a href="http://www.ghdhaironstyler.com/chi-red-hair-straightener-p-13177.html?cPath=481">ghd iv kiss styler</a> is another great feature<a href="http://www.ghdhaironstyler.com/chi-red-hair-straightener-p-13177.html?cPath=481">ghd iv ceramic hair straightener </a> of GHD hair straighteners. Once you plug it and switch it on, it can heat up in a very short time, providing you more time to do your hair. Because of all these wonderful benefits, hair <a href="http://www.ghdhaironstyler.com/pure-ghd-iv-styler-p-13183.html?cPath=487">ghd iv pure styler</a> salons all over the world use GHD stylers. However, there are different types of products available in this range. Following is a brief rundown on how to choose the most suitable one for you.<a href="http://www.ghdhaironstyler.com">http://www.ghdhaironstyler.com/
    </a>
    </body>
    </html>
  9. nhlbuy Says:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">;
    <html xmlns="http://www.w3.org/1999/xhtml">;
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>¢リヌc</title>
    </head>

    <body>
    <p>Once again, it's a pretty slow day for Met news. The most interesting story out there is Murray Chass's post on Omar's inability to multi-task this offseason. While I really despise anonymous sources, this does sound so stupid that it's probably true.</p>
    <p>Nelson Figueroa threw a complete game three-hitter in the Dominican Republic.Ted Berg has some great Val Pascucci video.For those Mets fans with more high brow tastes, <a href="http://www.nhlbuy.com/nfl-jersey-c-1.html?zenid=d5d388d6cbca033a03aa0ffd7bc10cf2">cheap nfl jersey</a>be sure to check out the Met poetry <a href="http://www.nhlbuy.com/nba-jersey-c-51.html">cheap adidas nba jerseys</a>reading on Feb. 16.</p>
    <p>Bobby Valentine will serve on a commission to improve Stamford's fire department. I hope for Stamford's sake that the solution will not involve Armando Benitez.Teddy Dziuba sat down with Met<a href="http://www.nhlbuy.com/mlb-jersey-c-34.html">discount mlb jersey</a> prospect Shawn Bowman who was recently<a href="http://www.nhlbuy.com/nba-jersey-c-51.html">cheap nba jersey</a> added to the Met 40 man roster.Around the NL EastThere is a really great Philadelphia joke in<a href="http://www.nhlbuy.com/nfl-jersey-c-1.html?zenid=d5d388d6cbca033a03aa0ffd7bc10cf2">wholesale football jersey</a> here somewhere, but I'm both too politically correct and not a <a href="http://www.nhlbuy.com/nhl-jersey-c-71.html">cheap nhl replica jersey</a>good enough joke writer to make it.Washington has signed Adam Kennedy, right after the O-Dog signed <a href="http://www.nhlbuy.com/nfl-jersey-c-1.html?zenid=d5d388d6cbca033a03aa0ffd7bc10cf2">new orleans saints jersey</a>with Minnesota. That means, once again, the Mets are stuck with Luis Castillo.<a href="http://www.nhlbuy.com/">http://www.nhlbuy.com/</a></p>;
    </body>
    </html>
  10. mbt women shoes Says:
    <a href="http://www.sharembt.com/mbt-changa-shoes-c-242.html">Mbt changa shoes</a> can help control weight, eliminating also believe and neck pain, injury, lazy. <a href="http://www.sharembt.com/mbt-lami-shoes-c-237.html">Mbt lami sale </a>manufacturers are also guaranteed main battle tanks will increase the wearer's posture and cheap.<a href="http://www.sharembt.com/mbt-womens-mwalk-c-1.html">mbt m walk shoe</a> tone muscles to help them.
  11. mbt shoes Says:
    mbt shoes made from high quality Nappa leather are strong and enduring.mbt shoes Best Prices available at cheap mbt shoes help to build body
  12. prescription glasses Says:
    I am looking forward for the next updates of your awesome worship.
  13. prescription eyeglasses Says:
    Thanks for your information!
  14. metal glasses Says:
    Thank you!
  15. gucci watches Says:
    The 82nd edition of the Oscars offered a reminder that no amount tag heuer watches of tinkering can match the magic of suspenseful competition. Even the awkwardly tag heuer rushed ending to the three-and-a-half-hour overlong telecast easily bvlgari watch was forgotten in the nail-biting moments in bvlgari watches which The Hurt Locker capped the evening with best bvlgari director and bvlgari picture wins.
    http://www.watchessell.com/product.php?id=17&categories_id=36
    http://www.watchessell.com/product.php?id=19&categories_id=36
    http://www.watchessell.com/product.php?id=21&categories_id=36
    http://www.watchessell.com/product.php?id=22&categories_id=36
    http://www.watchessell.com/product.php?id=25&categories_id=36
    http://www.watchessell.com/product.php?id=26&categories_id=36
  16. Nike Dunk Says:
    http://www.bytobyshop.com
    http://www.baysneaker.com
    http://www.okeywecan.com
    http://www.bytohere.com
    http://www.bellbestnike.com
    http://www.bellbestpuma.com
    http://www.bellbestugg.com
    http://www.bellbestadidas.com
    http://www.bellbestsupra.com
    http://www.bellbest.com
    http://www.oilpaintcharm.com

Leave a Reply



Powered by Mango Blog. Design and Icons by N.Design Studio