Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
carlu #1
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
-
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... -
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... -
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... -
[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... -
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... -
eastinq #2
Re: Question on generating CF code
Try evaluating the data.
#Evaluate(colScreenCode)#
eastinq Guest
-
carlu #3
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
-
eastinq #4
Re: Question on generating CF code
Try it one more time with DE() function.
#Evaluate(DE(colScreenCode))#
eastinq Guest
-
carlu #5
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
-
philh #6
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
-
carlu #7
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
-
Adam Cameron #8
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
-
carlu #9
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
-
carlu #10
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
-
eastinq #11
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
-
-
Adam Cameron #13
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
-
carlu #14
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
-
Adam Cameron #15
Re: Question on generating CF code
> following? <cfoutput #IIf(Form.Submit is
You can't do that.> 'add','','query='qryBoundaryAdjustmentsSelect''#>
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
-
carlu #16
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



Reply With Quote

