ColdFusion Config Settings
code, design, ColdFusion, CFCHere is the problem I needed to come up with a way to allow my client admins to set alias's for entry forms and report headers. So I started looking at localization and quickly found that, that was not a good Idea at all so then I started looking at using ini files since ColdFusion has functions for reading and setting config keys. I also found that I didn't like using the config file for this so I created a table to store the infromation. Then I decided to do some test to see if the was some benefit to using a DB verses the ini file low and behold there is.
This code block took [58ms] to run
<cftimer label="iniSettings" type="debug">
<cfscript>
iniFile = expandPath('config_1234_12.ini.cfm');
clientStruct ={
clientNameLabel = getProfileString(iniFile, "client", 'clientNameLabel'),
clientNameHasValidation = getProfileString(iniFile, "client", 'clientNameHasValidation'),
clientNameValidation = getProfileString(iniFile, "client", 'clientNameValidation')
};
</cfscript>
<cfoutput>
<label>#clientStruct['clientNameLabel']#</label>
<input type="input" name="clientName">
<input type="button" value="Click Me!" onclick="validate()">
<script>
function validate(){
<cfif IsBoolean(clientStruct["clientNameHasValidation"]) AND clientStruct["clientNameHasValidation"] is true>
#ReReplaceNoCase(clientStruct["clientNameValidation"],'~clientname~', clientStruct["clientNameLabel"])#
</cfif>
}
</script>
</cfoutput>
</cftimer>
This code block took [2ms] to run
<cftimer label="DBSettings" type="debug">
<cfscript>
args = {
cfSection = "client"
};
clientStruct=application.configSettingsService.queryToPropStruct(application.configSettingsService.getByAttributesQuery(argumentcollection=args));
if(StructKeyExists(clientStruct,'')){
}
</cfscript>
<cfoutput>
<label>#clientStruct['clientNameLabel']#</label>
<input type="input" name="clientName">
<input type="button" value="Click Me!" onclick="validate()">
<script>
function validate(){
<cfif IsBoolean(clientStruct["clientNameHasValidation"]) AND clientStruct["clientNameHasValidation"] is true>
#ReReplaceNoCase(clientStruct["clientNameValidation"],'~clientname~', clientStruct["clientNameLabel"])#
</cfif>
}
</script>
</cfoutput>
</cftimer>I know 58ms doesn't seem like much but remeber in this example its only one field and I have pages the have 50 fields that a client might alias.
ColdFusion Test
ColdFusion, testHere is a ColdFusion test that I found see how you do.
1. Which of these are NOT legal variable names?
a. $myVar
b. my-Var
c. _true
d. my$Var
e. false
2. What will this code produce?
<cfset test = RandRange(0, 1)>
<cfif NOT test>
<cfset x = Val(100/test)>
<cfelse>
<cfset x = Val(100/(test*0))>
</cfif>3. Write code to output 1 to 1000, comma-delimited, (stepping by 1) without using the
4. List as many ColdFusion application scopes as possible and explain each briefly.
5. Given a query “myQuery”, how would you get the column names that are returned by this query?
15. Given a query “myQuery”, how would you find out the total records returned by this query?
6. This is a query returned called “myQuery”:
Row Name Company
1 Jeff widget1
2 David Solisys
3 Darryl Adobe
4 Jim widget1
5 Marie Adobe
Write code to return the following output given the query above:
widget1
Jeff
Jim
Solisys
David
Adobe
Darryl
Marie
7. Given a query, "Products", with the fields: "id", "price", and "description", how can you output the price of the LAST row in the query without using either a loop or another query?
8. Given a custom tag, "ListNoDupes", that accepts the variables: "list" and "returnAs". The last line of the tag is this:
<cfset SetVariable('caller.' & attributes.returnAs, newList) />What will happen on the page that calls this custom tag?
a. Nothing
b. A variable called "caller.returnAs" will be set as a local variable on the calling page
c. A request-scoped variable called "newList" will be created
d. A local variable will be set on the calling page with the same name as the value of the "returnAs" parameter passed into the custom tag.
e. If no variable called "returnAs" exists on the calling page, it will be created. If such a variable does exist, nothing will happen.
9. Given this CFC:
<cfcomponent displayname="Classroom">
<cfset variables.students = ArrayNew() />
<cfset variables.teacher = "" />
<cffunction name="addStudent" returntype="void">
<cfargument name="student" type="Student" required="true">
<cfset ArrayAppend(getStudents(), arguments.student) />
</cffunction>
<cffunction name="getStudents" returntype="array">
<cfreturn variables.students />
</cffunction>
</cfcomponent>You create 1 "Classroom" object, "classroom", and 3 Student objects. You call the "addStudent()" method, passing in each of the three new students. At the end of this, what will this code produce?
#ArrayLen(classroom.getStudents())#
10. You've been given a text file, "CityTemperatures.txt". Each line in the file contains the temperatures for each day in the same week for different cities.
Atlanta: 54,57,52,34,45,49,53
Baltimore: 67,72,69,77,79,71,74
Chicago: 81,72,79,74,76,67,72
Denver: 68,64,75,69,72,63,68
Can you read and display the low, high, and average temperatures for each city in 10 lines of code or less?
11. You have a query, "Products", with the following columns: "id", "price", "description", and "quantityOnHand". You need to create a form with a checkbox for each row in the Products query, all using the name, "selectedProducts". The problem is that you need to send information about both the id of the product chosen AND the quantity on hand. At first, you think of putting a hidden form field for each query row that would contain this info, but your co-worker casually remarks that she always does this without using any more form inputs than there are rows. What's her secret?
12. Look at this code:
<cfset susie = StructNew() /> <cfset susie.employer = "ibm" /> <cfset me = StructNew() /> <cfset me.spouse = susie /> <cfset me.spouse.employer = "self-employed" />
What's the value of susie.employer?
13. You've produced a two-dimensional array, "arr", that you need to save as a client variable. What's the code for this?
14. Explain this code:
<cfdirectory action="list" directory="#ExpandPath('./images/mainpic/#ATTRIBUTES.MainPicDir#')#" sort="ASC" name="ImageList" filter="*.*">
<cfif ImageList.recordcount eq 1>
<cfoutput query="ImageList">
<img src="./images/mainpic/#ATTRIBUTES.MainPicDir#/#ImageList.name />
</cfoutput>
<cfelseif ImageList.recordcount>
<cfset randImageNum = randrange(1,#ImageList.recordcount#)>
<cfoutput query="ImageList" startrow="#randImageNum#" maxrows="1">
<img src="./images/mainpic/#ATTRIBUTES.MainPicDir#/#ImageList.name#" />
</cfoutput>
</cfif>
15. In the previous code, what is does ATTRIBUTES.MainPicDir stand for? What does the ATTRIBUTES scope for this variable mean?
Vids of the night
funny, video
Anonymous Philanthropist Donates 200 Human Kidneys To Hospital
In The Know: New Iraqi Law Requires Waiting Period For Suicide Vest Purchases
Polly don’t want crackers
The madam of a brothel has a problem, so she goes to a local priest. "I have two talking female parrots," she tells him. "All they can say is ‘Hi, we’re prostitutes. Do you want to have some fun?’"
"That’s awful," the priest agrees, "but I have a solution to your problem. I have two male parrots whom I’ve taught to pray and read the Bible. If we put your parrots with mine, I believe yours will stop saying that awful phrase and will instead learn to recite the word of God."
The next day, the madame brings her parrots to the priest’s house and puts them in with the male parrots, who are holding rosary beads and praying in their cage.
"Hi, we’re prostitutes." say the females. "Do you want to have some fun?"
One male parrot looks at the other and squawks, "Close the Bible, Frank! Our prayers are answered!"
Handleing Results in Model-Glue
code, ColdFusion, CFC, model-glueOk I am not the world’s best blogger but I am going to give a shot. So I am working on a Model-Glue Application that I started about a year and a half ago. And I am finally starting to reuse some of my functions. For example I have a saveUserAddress function and a saveUserAccount function and in both of these function’s I add result named success if there wasn’t an error. So here is the problem, we adding a new feature that allows a user to setup a new address and a new account on the same screen but in Model-Glue if there is a result the next function will not be called. So to fix this problem I added an argument to the message in the modelglue.xml file like so.
<message name="SaveUserAddress">
<argument name="addResult" value="false" />
</message>
<message name="SaveUserAccount" />Then in the controller component I add some logic to account for this.
<cfif arguments.event.ArgumentExists("addResult")>
<cfif arguments.event.getValue("addResult") EQ true>
<cfset arguments.event.addResult("success", true) />
</cfif>
</cfif>I know there some Mach-II guys out there so I would like to know how you handle this in Mach-II.






Loading....