Question on generating CF code

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Question on generating CF code

    Never thought I'd say it but I'm growing tired of typing basic cf code. I've
    created some tables and SPs to generate it for me but I'm having one problem.
    I came up with one solution that I didn't like and after searching haven't came
    up with anything better. There has to be something easy I'm missing so I'm
    hoping someone has a quick answer. Thanks ahead of time for any pointers.
    Basically what I have is a custom tag that pulls in generated cf code from a SP
    and cfoutput. The problem is that the cfoutput is processed and the cf code is
    put inline after which the cf service has passed off processing to the web
    service and the generated code never passes through the cf service to generate
    the needed html. End result is cf tags in my html source (right click, view
    source). Code basically is... <cfstoredproc procedure='uspScreenBuilder'
    datasource='someDSN#'> <cfprocresult name='qryScreenBuilder' resultset='1'>
    <cfprocparam value='uspBoundaryAdjustmentsSelect' cfsqltype='cf_sql_varchar'
    type='In'> <cfprocparam value='insert' cfsqltype='cf_sql_varchar' type='In'>
    </cfstoredproc> <cfoutput query='qryScreenBuilder'> #colScreenCode#
    </cfoutput> The cf code comes from the #colScreenCode# so it is never
    processed into html. Oh, the one idea I had was to create a temp file and
    include that but that seems like a lot of overhead. This is already doing
    enough processing. I probably would not consider something like this on a site
    that had 100s of concurrent users. Thanks much and have a great one Carl

    carlu Guest

  2. Similar Questions and Discussions

    1. Generating HTML code in the code-behind
      Can I do this? I'm playing with AJAX, and it occurred to me that it'd be a lot easier to make changes to a control on the server, grab the HTML...
    2. Generating the Web Service code from C# class.
      Hi, I have a C# class and I have to expose it through a Web Service, but I don't want to write the Web Service, is there a generator that can...
    3. Generating gradients in odd shaped paths (Question)
      This may be a newbie question so forgive me. I am using Illustrator 10 and occassionally find the need to create a gradient inside an odd shaped...
    4. [ba-rb] BA-rb ( Bay Area Ruby Users Group ) - 'Generating Code in Ruby' by Jack Herrington.
      Count me in again, too. -- Jos Backus _/ _/_/_/ Sunnyvale, CA _/ _/ _/ _/ _/_/_/ _/ _/ _/ _/ jos at...
    5. BA-rb ( Bay Area Ruby Users Group ) - 'Generating Code in Ruby' by Jack Herrington.
      BA-rb (Bay Area Ruby language Users Group) is pleased to announce that it will begin meeting again. The topic for the first meeting will be a...
  3. #2

    Default Re: Question on generating CF code

    Try evaluating the data.

    #Evaluate(colScreenCode)#

    eastinq Guest

  4. #3

    Default Re: Question on generating CF code

    Thanks for the quick reply. I had tried that and this is the message I get
    Error Detail: ColdFusion was looking at the following text: < The CFML
    compiler was processing: < marks the beginning of a ColdFusion tag.Did you
    mean LT or LTE? This is a sample of what the SP is returning... <cfinput
    name='PermitID' type='hidden'> <table> <tr> <td> Permit Number </td> <td>
    <cfinput name='PermitNumber' type='text' size='11' maxlength='11'
    required='yes'> </td> <td> Application Date </td> <td> <cfinput
    name='ApplicationDate' type='text' size='10' maxlength='10' required='yes'
    validate='date'> </td> <td> (mm/dd/YYYY) </td> </tr> </table>

    carlu Guest

  5. #4

    Default Re: Question on generating CF code

    Try it one more time with DE() function.

    #Evaluate(DE(colScreenCode))#

    eastinq Guest

  6. #5

    Default Re: Question on generating CF code

    Did that and got the same thing as having nothing there but #colScreenCode# The
    thing is that I need cf to treat the results of query as if it was inline. As
    it is if I copy the query results into a .cfm page it would work fine. Make
    sense?

    carlu Guest

  7. #6

    Default Re: Question on generating CF code

    OK, here's the short answer: Cold Fusion code has to live in a ColdFusion
    template in order to be processed by the service. It's that simple. Anything
    that doesn't live in the template before it's processed is treated as
    information to be manipulated, not Cold Fusion tags and functions to be
    processed. Some folks have a scheme where the 'code' in your database is
    written out to a temporary CFM template,and then that created-on-the-fly
    template is called or included. Seems like a lot of trouble.

    philh Guest

  8. #7

    Default Re: Question on generating CF code

    Seems like a lot of trouble I agree which is the other reason I don't want to
    do it that way. Along with my reason in the original post of it being to much
    overhead. I suppose probably not that much more overhead compared to what I'm
    already doing. Althought my code isn't in the database, just the metadata, the
    SP creates the code. This really sucks!

    carlu Guest

  9. #8

    Default Re: Question on generating CF code

    >Seems like a lot of trouble.

    Whether or not it's a good idea, exactly how much trouble is it? You write
    a UDF ONCE to do it for you. That's it.

    If that's a lot of trouble... you must lead a very charmed life, and I am
    terribly jealous of you.

    On a serious note... one thing to watch when doing this is the code needs
    to be translated (I'm resisting the urge to say "compiled" here) from CFML
    source code to Java bytecode before it's executed. With static CFML files,
    this is done once, and either stored as a class file or in RAM; thereafter
    the bytecode is executed when the CFML template is called (rather than
    re-translating it every time, I mean). This can't be done with dynamically
    created files; they have to be translated every time before they're
    executed. And then they clutter up the server memory and possibly the
    cfclasses directory as well.


    Now: back to the original question again.

    I can't quite understand your approach here. You're passing CFML into a SP
    which monkeys around with it; I guess inserting some more CFML and then...
    returning some raw CFML. Even if this was to work (which, you know, it
    won't), how would this differ from the more usual approach of having a
    dynamic CFML template which is used in conjunction with some DB data to
    generate HTML? What am I missing here?


    --

    Adam
    Adam Cameron Guest

  10. #9

    Default Re: Question on generating CF code

    Not much work which is why I'm working on it. The part I didn't like was the
    tempory template idea. I have in some table all info needed to generate basic
    form cfinputs. Stuff like name, type (text, dropdown, hidden, etc), validation
    type (date, integer, phone, zip, etc), size, display size, required, and SP
    names to populate any dropdowns. A stored procedure creates the output just as
    I would have had to type the code into a .cfm file for my form. Based on the
    action (insert, update, delete) the SP will do different things (like include
    the value='#x#' for updates). The only two parameters the SP gets is the name
    of a select SP (which is used to link the tables together) and the action. No
    cf code is passed into the SP. It will save a little time upfront when first
    creating pages for data entry/maint but best part is in maintenance where
    changes are requested. They can be made in the metadata and that is it. No
    changing multiple .cfm files and hoping all occurances were found. Now I did
    get an idea from what you said on 'the more usual approach'. I could pull the
    logic out of the SP and put it into one or more templates and just use queries
    to the metadata to control the flow of logic. Thanks Carl

    carlu Guest

  11. #10

    Default Re: Question on generating CF code

    While thinking about taking the logic out of the SP and putting it into CF this
    is one of the problems. In MSSQL SP I have this bit of code from which you can
    see the label is very simple and easy to do in CF as well (there is no logic
    needed for the output). The text type is a different story. With four
    variables (standard text input tags, requrired, validate and value... you all
    can figure that out with stat math) is a problem with CF because you can't put
    a cfif inside of a cfinput tag (unless I missed something). If I could do the
    following then it wouldn't be a problem <cfinput name='#colName#'
    type='#colType#' size='#colDisplaySize#' maxlength='#colSize#' <cfif
    '#colRequired#' IS '1'> required='yes' </cfif> >

    If @curType = 'label'
    Begin
    Set @hldScreenCode = @curName
    Goto writeRowTypeExit
    End
    If @curType = 'text'
    Begin
    Set @hldScreenCode = '<cfinput name="' + @curName + '" type="' + @curType
    + '" size="' + cast(@curDisplaySize as varchar(4)) + '" maxlength="' +
    cast(@curSize as varchar(4)) + '"'
    If @curRequired = 1
    Begin
    Set @hldScreenCode = @hldScreenCode + ' required="yes"'
    End
    If @curValidateType > ''
    Begin
    Set @hldScreenCode = @hldScreenCode + ' validate="' + @curValidateType +
    '"'
    End
    If @Action = 'update'
    Begin
    Set @hldScreenCode = @hldScreenCode + ' value="#col' + @curName + '#"'
    End
    Set @hldScreenCode = @hldScreenCode + '>'
    Goto writeRowTypeExit
    End

    carlu Guest

  12. #11

    Default Re: Question on generating CF code

    This is what I've done in those situations.



    <cfinput name="#colName#" type="#colType#" size="#colDisplaySize#" maxlength="#colSize#" required="#IIf(colRequired is '1',DE('yes'),DE('no'))#">
    eastinq Guest

  13. #12

    Default Re: Question on generating CF code

    Thanks :)

    I'll give that a try.
    carlu Guest

  14. #13

    Default Re: Question on generating CF code

    Err...

    .... just don't use <cfinput>? If you need any of the JS validation, you
    can just grab it from cfform.js, the view-source of a rendered template
    that used <cfinput>, or just roll your own.

    All <cfinput> gives you is badly implemented, bloated, generically-written
    JS validation. It's much better to write your own validation (perhaps
    using the <cfform>-generated stuff as a starting point.

    --

    Adam
    Adam Cameron Guest

  15. #14

    Default Re: Question on generating CF code

    Working with some of the ideas from here. Can someone help me out with the
    following? <cfoutput #IIf(Form.Submit is
    'add','','query='qryBoundaryAdjustmentsSelect''#> <cfoutput
    query='#IIf(Form.Submit is 'add','',DE('qryBoundaryAdjustmentsSelect'))#'> I
    get an error on the first # on the first one and a 'String index out of range:
    0' on the second one. Basically what I have is a screen that does both inserts
    and updates. For the updates I need the cfoutput to dump the current values
    into the input fields but for the inserts I don't so I figured cfquery w/o a
    query wouldn't hurt anything. Maybe there is a better approch that I've not
    yet seen. Any ideas? Thanks very much in advance Carl

    carlu Guest

  16. #15

    Default Re: Question on generating CF code

    > following? <cfoutput #IIf(Form.Submit is
    > 'add','','query='qryBoundaryAdjustmentsSelect''#>
    You can't do that.

    CF ain't lego... you can't just chuck tags together piece by piece,
    building the tag with other CF logic.

    You need to decide which mode you're in, and have separate output blocks
    for each.

    --

    Adam
    Adam Cameron Guest

  17. #16

    Default Re: Question on generating CF code

    Having separate output blocks is double code! Kinda the hole point of my
    questions here (reducing the amount of code to type). On another note...
    Thanks for the tip on doing my own validation. I've thought about it but just
    haven't take the time to do it yet (my javascript skills are not great and I do
    most validation in the SPs). After looking at it again it doesn't look to bad
    so maybe my javascript is better than last time I looked at doing it ;) SO,
    does everyone just code separate output blocks duplicating code (one with the
    value='#xyz#' and cfoutput for updates and one w/o value and cfoutput for adds)?

    carlu Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139