Skip to main content
Participating Frequently
November 19, 2009
Question

Reusing Form Controls

  • November 19, 2009
  • 2 replies
  • 500 views

Hey Everyone,

Can I get some suggestions on the best way for resuing form controls?  Currently, I am resuing form controls via cfinclude files.  Within the cfinclude files the controls are populated via cfc's.  Performance-wise is it best to ouput html from cfc's or not?  How about reusing bound controls (ie. a drop down predicates options in a list box).  I come from the school where it's desireable to seperate your business logic from your html content as much as possible. I am hesitant outputting html content from cfc's.

Thanks

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    Community Expert
    November 19, 2009
    I come from the school where it's desireable to seperate your business logic from your html content as much as possible.

    Not for nothing. I would even go as far as to say, if you find yourself pumping HTML out of a CFC, then you're definitely doing something wrong.

    Using a cfinclude or a CFC is not reuse. Writing a cfinclude or CFC code that gets used over and over in your site, that's reuse. A form page that has a cfinclude that invokes a CFC that supplies data to the form is already a design that you can, and have to, simplify.

    jcaleyAuthor
    Participating Frequently
    November 19, 2009

    Using a cfinclude or a CFC is not reuse. Writing a cfinclude or CFC code that gets used over and over in your site, that's reuse.

    Err, yeah I am including files that contain form controls for reuse. Over and Over.

    A form page that has a cfinclude that invokes a CFC that supplies data to the form is already a design that you can, and have to, simplify.

    I have to simplify? Lets's say you have one <cfselect> predicated on the selection of another <cfselect> using ajax (ie cfc - w/a function access set to "remote").

    If I want to resuse these two controls over and over, what is the best way to do so?  Right now I am including each control.

    I am looking for a better way.  If you have a suggestion it would be appreciated.

    Inspiring
    November 20, 2009

    What you are doing now seems about as good as it gets for your own situation.

    ilssac
    Inspiring
    November 19, 2009

    There is nothing technically or preformance wise wrong with outputting HTML from a CFC.

    To keep your layers seperate so your business logic is not mixed with your display (html) logic, just use differerent CFCs.

    Many ColdFusion developers feel that custom tags are a more natural fit for the display layer, but this is more or less an aesthetic opinion then anything technical.

    I.E.  Many people think this looks more natural.

    <cf_myDisplayLogic param1="aValue" param2="bValue">

    Then this

    <cfset displayObj = createObject("component","path.to.myDisplayLogic")>

    <cfoutput>#displayObj.showStuff(aValue,bValue)#<cfoutput>

    But they both are perfectly fine examples of seperation of logic.