Sometimes we forget our CF Admin password or due to some reason you are not able to login to your ColdFusion Admin, so how to reset your CF Admin password.
Before ColdFusion 10 there was no such tool to reset CF Admin password but in ColdFusion 10 Adobe provides a tool to reset the password. Lets see how can we reset...
As shown in the above image go to command prompt and then go to "{CF-ROOT}\cfusion\bin" and run "dir" then you can see list of files present in that directory. There is a file present called "passwordreset.bat" and run that file. You will see another screen as below:
For changing CF Admin password enter "1".
Follow the instructions to reset both CF Admin and RDS password then restart your CF server and you are done!!!
Tips and Tricks for ColdFusion and Other Web Technologies like Java, jQuery, DataBase
Showing posts with label ColdFusion 10. Show all posts
Showing posts with label ColdFusion 10. Show all posts
Sunday, February 16, 2014
Thursday, December 12, 2013
Display login screen in browser when session time out for a user using Web Socket
If you will notice the ColdFusion Administrator of CF10 then you can find that in some intervals of time it keeps refreshing. Though I am not sure why it is refreshing but I believe that refresh option is added just to take user to login screen when session time out occurs.
Let say you are using some chatting application and you have opened different chat window in different tabs and you logout from the application and you forgot to close other chat window tabs. The other chat tab which is opened may have some sensitive/private information which others can view. So, ideally we should view the login screen in all tabs once a user manually logs out or when the session timeout occurs.
We can show user login screen in all tabs when session timeout occurs/logs out by the user by using one of the following ways.
- Keeps refreshing our page in some intervals of time and when session times out then you will automatically redirect to login screen. But this may create issues like content reload unnecessarily.
- Keep making AJAX call to server to verify login status in some intervals of time and reload the page whenever required. This is correct upto some extent okay but we have to make AJAX call in some intervals of time, i,e - some extra burden.
- Use Web Socket to achieve the functionality without refreshing the screen in some intervals of time.
For #1 and #2 time interval will be more than the session timeout time.
I think #1 and #2 is not the optimized way of do that. So, lets see how we can achieve that using ColdFusion Web Socket and I think this is one of the best method to achieve this.
Before I move ahead please download the application here.(Login Tracking By WebSocket.)
***NOTE: Attached code will work only in ColdFusion 10
Create a Web application in your computer using the above code and use any email ID and Nick name to login into the Application.
Code Description:
Code contains inline comments and I am describing the whole logic below.
How Does the Code Works:
We have defined a channel "Logout" in Application.cfc. Using this channel we can create no of sub channel of it in our application.
Logout.onLineUser - This channel no of currently online users in this application.
Logout.{email ID Login User} - This channel identifies whether a user is log in or log out from the system.
Step 1: (Login Page and Login Process)
- Display Login Screen to user if the user is not log in into the system.
- Take email ID and nick name to allow user to log in into the system and save the email ID in Application scope,
a) so that other user can able to see online users of the Application at any time
b) Make email validation, i.e :- Multiple login of same email ID is blocked at a time.
- Publish the online users into "Logout.onLineUser" channel.
- Redirect to index.cfm page.
Step 2:(index.cfm page and Display Online User)
- Load all online users from "Application.userInfo" variable.
- Initiate two channels: 1. Logout.onLineUser 2. Logout.{email ID} (Here we are removing "." and "@" from the email ID while creating sub channel)
- onLineResponseHandler : - In online user handler we will write the logic, if we are receiving data from user then display all the online user information received in UI.
- logoutResponseHandler: - In this response handler we will receive data if the user logout from the system. So, reload the page. As the session is undefined it will take you to the login screen.
Step 3:( Log out Functionality)
- In index.cfm we have added a logout link. If you click on that link then it will take you to logout.cfm and then it calls logoutUser method present in Utility.cfc.
- logoutUser() we are taking two parameter.
1. Application scope.
2. Login Info Structure from Session scope.
- We are deleting the user information from "Application.userInfo".
- We are clrearing the Session Scope and publishing login status of the user to
- Publish all available user information to "Logout.onLineUser" channel. So that all active users can see the online status at that instant.
- Publish login status of the currently logout user to channel "Logout.{email ID}" and in JS code after getting the status the page will be reloaded, as the session is already cleared then it will redirect to login page.
Step 4: Auto Log out by Session timeout
- When session time out wil happen then we are calling "logoutUser()" from onSessionEnd().
- In logoutUser() method we are just deleting the user information from Application.userInfo and publishing the logut status to reload the browser if that is opened.
Hope you have enjoyed!!!
Before I move ahead please download the application here.(Login Tracking By WebSocket.)
***NOTE: Attached code will work only in ColdFusion 10
Create a Web application in your computer using the above code and use any email ID and Nick name to login into the Application.
Code Description:
Code contains inline comments and I am describing the whole logic below.
How Does the Code Works:
We have defined a channel "Logout" in Application.cfc. Using this channel we can create no of sub channel of it in our application.
Logout.onLineUser - This channel no of currently online users in this application.
Logout.{email ID Login User} - This channel identifies whether a user is log in or log out from the system.
Step 1: (Login Page and Login Process)
- Display Login Screen to user if the user is not log in into the system.
- Take email ID and nick name to allow user to log in into the system and save the email ID in Application scope,
a) so that other user can able to see online users of the Application at any time
b) Make email validation, i.e :- Multiple login of same email ID is blocked at a time.
- Publish the online users into "Logout.onLineUser" channel.
- Redirect to index.cfm page.
Step 2:(index.cfm page and Display Online User)
- Load all online users from "Application.userInfo" variable.
- Initiate two channels: 1. Logout.onLineUser 2. Logout.{email ID} (Here we are removing "." and "@" from the email ID while creating sub channel)
- onLineResponseHandler : - In online user handler we will write the logic, if we are receiving data from user then display all the online user information received in UI.
- logoutResponseHandler: - In this response handler we will receive data if the user logout from the system. So, reload the page. As the session is undefined it will take you to the login screen.
Step 3:( Log out Functionality)
- In index.cfm we have added a logout link. If you click on that link then it will take you to logout.cfm and then it calls logoutUser method present in Utility.cfc.
- logoutUser() we are taking two parameter.
1. Application scope.
2. Login Info Structure from Session scope.
- We are deleting the user information from "Application.userInfo".
- We are clrearing the Session Scope and publishing login status of the user to
- Publish all available user information to "Logout.onLineUser" channel. So that all active users can see the online status at that instant.
- Publish login status of the currently logout user to channel "Logout.{email ID}" and in JS code after getting the status the page will be reloaded, as the session is already cleared then it will redirect to login page.
Step 4: Auto Log out by Session timeout
- When session time out wil happen then we are calling "logoutUser()" from onSessionEnd().
- In logoutUser() method we are just deleting the user information from Application.userInfo and publishing the logut status to reload the browser if that is opened.
Hope you have enjoyed!!!
Labels:
ColdFusion,
ColdFusion 10,
WebSocket
Monday, November 11, 2013
Generate Report Using ColdFusion Report Template
In my following posts we learned up to creating a report template using ColdFusion report builder.
Place the ".cfr" file in your project directory. See the following code to use the report template.
In the first section, I have written a SQL query for report then I am using the report template in cfreport tag to generate/display the report.
Here, if we will not use any query then it will display the report of the query which we had used during creating the report. If we are passing any query object to the cfreport tag then it will only consider the query object.
So, by using a customize queries we can generate multiple reports of the same type using ColdFusion reporting template. We can also pass parameter to a report. We will learn that in my future post.
Generated Report Screen Shot:
- Starting with Report Builder.
- Set up ColdFusion server in ColdFusion Report Builder.
- Creating a simple report template using ColdFusion Report Builder.
Place the ".cfr" file in your project directory. See the following code to use the report template.
In the first section, I have written a SQL query for report then I am using the report template in cfreport tag to generate/display the report.
Here, if we will not use any query then it will display the report of the query which we had used during creating the report. If we are passing any query object to the cfreport tag then it will only consider the query object.
So, by using a customize queries we can generate multiple reports of the same type using ColdFusion reporting template. We can also pass parameter to a report. We will learn that in my future post.
Generated Report Screen Shot:
Labels:
ColdFusion,
ColdFusion 10,
ColdFusion Rport Builder
Creating a Tabular Report using ColdFusion Report Builder
In my previous two post we just learned how w just installed
Report Builder and then connect Report Builder with our ColdFusion server.
If you want to see old posts please go from here #1(Report Builder installation) and #2(Set up Server in Report Builder)
So, now it’s time to go for a simple example of ColdFusion
reporting using Report Builder. Please follow the steps to generate a tabular
report and use that in ColdFusion code.
Click on File
-> New in Report Builder, you will see a screen like below:
Go with “Report Creation Wizard” and click on “OK”.
You will see a next screen like below:
Click on “Query Builder” button.
Then we will see a new Query Builder screen for
our report.
As shown in the picture, you can see all the available data
sources and also you can write your own customize SQL query in the mentioned
section. There is button “Test Query”.
You can also test the query output by clicking that button. If your query has
any problem then it will display error message.
After writing your SQL query just click on “Save” button.
Then you will see another screen like below:
Here, you can select query columns which
you want to in printable report.By using right side "Up" and "Down" arrow you can place column in a defined order. For now just forget it and click on “Next”.
·
We will see another screen as below:
Here, you can define any order by fields in your report. Let
say I want to see first all arts which is not yet sold. By using the extreme
right Up and Down arrow you can define the direction of the order by clause. Here,
I want to see all sold items first so I made as descending order. It depends on
your choice.
Click on “Next” to go
to next screen.
·
Here is our next screen:
Just select the option as you see in screen and then click
on “Next”. You will see another
screen after that then click on “Next”.
·
You will see the next screen like below:
Here, in the text fields you have to put some descriptive
name about your report. See the label and put the description text accordingly
then click on “Finish”.
·
After, all these set up finally you see some
different window like below:
In this screen we can customize our report header text and
we can also format the display text in report.
Let’s see how we can do that:
First click on #1: A new window will pop up like below
Here, I have used ColdFusion DateFormat() to formatting the displaying date.
Click on #2: A new pop up window will be displayed:
Here, I just changed column header from “ISSOLD” to “Sold”. So similarly we can change all the column header with some
descriptive name.
Click on #3: A new pop up window will appear like below:
Here, we just used another ColdFusion function for display
formatting of a field value. Similarly, you can apply your own logic on other
fields if you want.
I have changed the column header and added display
formatting function for header and cell values. Finally we will have the following
screen:
Here, field names are changed and we can also see the
display formatting function in applied area then click on preview button to see the preview of
the report. Then save the report. It will generate a “.cfr” file.
Next, how we will use generated template in our ColdFusion code. Go here...
Next, how we will use generated template in our ColdFusion code. Go here...
Labels:
ColdFusion,
ColdFusion 10,
ColdFusion Rport Builder
Server Set up in ColdFusion 10 Report Builder
When we first run Report Builder then we will see screen for server set up
otherwise by clicking on
File - > New, we will see a screen like below.
Here we have to select "Server Setup Wizard" as highlighted then
click "OK" it will take you to the server set up screen(as shown
below).
Click "Next" in above screen then you will see another screen as
shown below.
In this screen, you can see "Measurement Units" drop down. It
shows different scale, you have to select one which you want to use in your
report. Then click "Next". You will see another screen like below.
In above screen, we have to provide server details to which want to
connect.
- Description: Any Name for identifying that server.
- Host Name: IP/Server Name
- Port: Port no on which your coldfusion is running. For me it's 8500
- Use SSL check box, content Root, RDS Security(User Name), if it is required for you.
- Password: Provide RDS password which you have set up in ColdFusion Admin.
After all these values click on "Test Connection" to see if you
are able to connect to server or not. Then you will see a screen like below.
Here everything is fine for me. If you are facing any problem please check
again the values you are providing and also check whether RDS is allowed in the
target server and if the server is running or not. Then close the screen and click on "OK" button. You will see
below screen.
Here in above screen you can see in CF Server label "CF10 Local"
is selected which we just set up. Also, you can see two other fields,
- Local Webroot: Web root of the server which you have selected.
- Website Webroot: Exact URL root to browse any file on that server.
You can follow the instructions and the example I am showing you for
reference. Then Click on "Next" button, you will see a screen like below.
So, all your set up is done just click on "Finish" to complete
the process or "Previsous" to change anything.
We have linked a server to the Report Builder then what's next???
Let's try a simple report template with Report Builder here. Go here....
Labels:
ColdFusion,
ColdFusion 10,
ColdFusion Rport Builder
Starting With ColdFusion Report Builder
I think most of you have heard something about report builder in different
tools like SQL server report building tool and other report building tools for
different languages.
In ColdFusion, we also have a report building tool
called “ColdFusion Report Builder”. So, lets explore about it.
What is a Report Building ?
Report building means to represent some information in graphical way ex:- different kinds of chart or tabular
format.
I will cover basic things of ColdFusion Report
building. I have
divided the report building topic into following sections:
2. Set up Server in Report Builder.
3. Creating a Sample Report Template.
4. Use ColdFusion Report Template in ColdFusion
3. Creating a Sample Report Template.
4. Use ColdFusion Report Template in ColdFusion
1. Installing ColdFusion 10 Report Builder:
- You can download ColdFusion 10 Report Builder
from following URL:
- Double click on the exe file and follow the
instructions to install.
- In Windows 8/Windows 2012 server you may
see following error message:
Installer user interface mode
not supported
Please follow below mentioned steps to avoid this error.
- Right
click on the installer then you will see a screen like below.
- Select “Troubleshoot
Compatibility” then you will see a trouble detecting screen and after few
seconds you will see following screen.
- From the above
screen select “Try recommended settings”.
Then you will see following next screen.
In above screen
you have to click on “Test the program”
then it will be installed successfully.
Next, after installation set up server in Report Builder. Go here to know details....
Labels:
ColdFusion,
ColdFusion 10,
ColdFusion Rport Builder
Thursday, October 31, 2013
Creating a Random Captcha with refresh Option
We all know that creating captcha is not a tough job in ColdFusion. But, one newbie in ColdFsion just asked me to help in creating a random captcha for his application.
I thought to share with others.
I have divided the entire code into three parts.
I thought to share with others.
I have divided the entire code into three parts.
- captcha.cfm - Page where we will display the captcha image.
- Util.cfc - It contains a user defined function "generateRandomText" to generate random captcha text.
- refreshCaptcha.cfm - Page which will handle AJAX call while refreshing captcha image.
Lets see the "captcha.cfm" below:
Here, in above code I have used "ImageCreateCaptcha" function, which is added in ColdFusion 10 for captcha generation.
Lets see the "Util.cfc"
In this file, I have written a function called "generateRandomText" for generating captcha string. Logic is very simple, you can modify it according to your requirement.
Next, come to "refreshCaptcha.cfm":
We are making AJAX call to this file which again generates random captcha image and sends to browser for display.
So, this is whole story for generating and refreshing captcha image in ColdFusion!!!
Lets see the "Util.cfc"
In this file, I have written a function called "generateRandomText" for generating captcha string. Logic is very simple, you can modify it according to your requirement.
Next, come to "refreshCaptcha.cfm":
We are making AJAX call to this file which again generates random captcha image and sends to browser for display.
So, this is whole story for generating and refreshing captcha image in ColdFusion!!!
Saturday, October 12, 2013
Post Parameters Exceeds Maximum Limit
In sometime
I was making a “POST” AJAX request to server and it was working fine but latter
I had to add few new form elements and then I made the POST AJAX call. Suddenly
I got the error:
HTTP Error 500.0 - Internal Server Error
The page cannot be displayed because an internal server
error has occurred.
I was using ColdFusion – 9 with IIS. After few searching I
found that the problem is with no of form parameters present in the “POST”
request. By default ColdFusion provides a default form element limit as “100”. If
the no of parameter will exceed to that then we will get error message.
I run the same code in ColdFusion – 10 with Apache and I got
the following error message:
POST parameters exceeds the maximum limit.
POST parameters exceeds the maximum limit.
Then the question arises:
–
Will I get the same error for “GET” request?
–
How can I increase the limit in ColdFusion?
Will I get the same error for “GET” request?
No, for “GET” request you will not get such error . “GET”
request depends on the URL length. I mean when you make any “GET” request all
parameters are appended to the base URL and they pass in URL scope. Each
browser have some limit to length of the URL it can process, if the URL length
in “GET” request will exceed to that then you may get some error message or
some unwanted result.
How can I increase the limit in ColdFusion?
In
ColdFusion – 9:
First install the security fix( http://helpx.adobe.com/coldfusion/kb/coldfusion-security-hotfix.html ) for ColdFusion - 9.
Go to {ColdFusion-Home}/lib for Server Installation
or
{ColdFusion-Home}/WEB-INF/cfusion/lib for Multiserver or J2EE
installation.
Open file neo-runtime.xml, after the line.
<var
name='postSizeLimit'><number>100.0</number></var>
add the below line and you can change the number 100 to your
desired limit.
<var
name='postParametersLimit'><number>100.0</number></var>
In ColdFusion – 10:
Adobe has added an option in ColdFusion Admin to control the
number of form elements. Go to
“Settings”, you will see a screen like below:
You can change the highlighted section value from “100” to
your desired form element limit.
NOTE: After doing all these you will see if you
have provided “100” limit then you are able to pass only “99” form elements in
post request I.e. 1 element less than the limit. Because when do any form post
ColdFusion automatically added a field called “FIELDNAMES”.
ArrayEach() And StructEach() In ColdFusion 10
Today I was looking into new functions added ColdFusion 10
and I found two interesting functions. So, I thought to share those functions.
-
ArrayEach()
-
StructEach()
1.
ArrayEach(array, HandlerFunction( Any
currentObj){})
“ArrayEach” is used to loop over an array object and the
Handle Function can have each element of the
array during looping. So, we can apply our business logic in side the
handler function. We can write the handler function as inline function or a named
function which we can reuse in multiple cases.
Lets see the example:
<cfscript>
dispObj = new Display();
arr = [1,2,3,4,5,6,7,8,9,10];
WriteDump(arr);
function showArrayElement( elem ) {
Writeoutput(elem
& '<br>');
}
//Calling an inline
function during loop over an array
arrayEach(arr,
function(currentObj) { Writeoutput( currentObj & '<br/>' ); });
//Calling a named function during looping over the array
arrayEach(arr,
showArrayElement);
//Calling a named function by object during looping over the array
arrayEach(arr, dispObj.showArrayElem);
</cfscript>
After running the above code I got the following output.
2. StructEach(
structure, HandlerFunction( key, value )
{})
Similarly like AyyayEach() here we can loop over a structure
elements where the handle function have the key and value. Using the handler
function we can implement our business logic.
Lets see the code:
<cfscript>
dispObj = new Display();
struct = {name: "Upendra", place: "Hyderabad",
technology: "coldfusion", time: "12:53PM"};
Writedump(struct);
function showStructElement(key, value) {
Writeoutput(
key & ':' & value & '<br/>' );
}
//Calling an inline
function while looping over the struct
structEach( struct,
function(key, value) { Writeoutput( key & ':' & value & '<br/>' ); } );
//Calling a named function during looping over a structure
structEach( struct,
showStructElement );
//Calling a named function by object during looping over a
structure
structEach( struct,
dispObj.showStructElement );
</cfscript>
After running above code we will get the following output:
***NOTE: In the output I have not displayed the result of named function call by creating object of a component as it would produce same result as general named function call.
Display.cfc
component
output="true"{
function
showArrayElem( elem) {
Writeoutput(elem
& '<br>');
}
function
showStructElement(key, value) {
Writeoutput(
key & ':' & value & '<br/>' );
}
}
Labels:
ColdFusion,
ColdFusion 10
Wednesday, July 03, 2013
The processing instruction target matching "[xX][mM][lL]" is not allowed.
I was doing some operation on some XML document and I got a strange error :
"The processing instruction target matching "[xX][mM][lL]" is not allowed. "
I just regenerated the error with the following code sample.
Then I searched in web I found that this is not related to any specific language, this is related to the XML declaration format.
According to the XML spec we can't have anything at all before the XML prolog. In our XML we are staring with XML declaration. So, that XML declaration should be the first character in our XML document no white space or any special characters are allowed before our XML document declaration.
So, the question is how we can avoid this in our above code?
- Use trim before parsing the XML string like below
<cfset mydoc = XmlParse(trim(request.x))>
So, trim function will remove any extra spaces present in the document before starting the XML declaration.
- Write XML declaration as the first character of your XML text. No white space or any other characters at the starting position.
- Remove your XML declaration from the XML text.
Hope it will save your time...
"The processing instruction target matching "[xX][mM][lL]" is not allowed. "
I just regenerated the error with the following code sample.
Then I searched in web I found that this is not related to any specific language, this is related to the XML declaration format.
According to the XML spec we can't have anything at all before the XML prolog. In our XML we are staring with XML declaration. So, that XML declaration should be the first character in our XML document no white space or any special characters are allowed before our XML document declaration.
So, the question is how we can avoid this in our above code?
- Use trim before parsing the XML string like below
<cfset mydoc = XmlParse(trim(request.x))>
So, trim function will remove any extra spaces present in the document before starting the XML declaration.
- Write XML declaration as the first character of your XML text. No white space or any other characters at the starting position.
- Remove your XML declaration from the XML text.
Hope it will save your time...
Labels:
ColdFusion,
ColdFusion 10,
ColdFusion 9,
XML
Tuesday, July 02, 2013
Restart your Application without restarting your ColdFusion Server
I was working in a old application where the object instantiate was done in onApplicationStart method of Application.cfc. To solve few hot fixes I modified the cfc and pushed into live but the code which I had modified was not working. As I have to reset that application variables which holds the Old component object.
So, I thought use ApplicationStop function which was introduced in ColdFusion-9. Before that I have never used ApplicationStop in any of my previous applications. I had read the documentation that this function basically used in ColdFusion ORM to reload the ORM objects. So, I just did some testing how exactly this function behaves in normal condition.
So, here is my Application.cfc for testing.
Here is index.cfm
If you will notice here in this Application.cfc I just doing file append operation in onApplicationStart(), onSessionStart(), onSessionEnd(), onApplicationEnd() and also inside onRequestEnd() when we want to refresh our application.
When the very first time I run the application I got the following output in file write:
Application started on :- {ts '2013-07-02 18:28:04'}
Session started on :- {ts '2013-07-02 18:28:04'}
And for index.cfm I got the following output:
Testing Application Stop
10
20
Next time I just passed a URL parameter "appReset" so that I can reset the application. Then I got the following output in file write:
Application stop is going to execute on :- {ts '2013-07-02 18:28:49'}
Application ended on :- {ts '2013-07-02 18:28:49'}
And in index.cfm I got the following output:
Testing Application Stop
10
20
So, here we observed that ApplicationStop() executed and then onApplicationStop() executed but onSessionEnd() was not executed.
On third time I just removed the URL parameter for Application reset. Then I got the following output:
In log file:
Application started on :- {ts '2013-07-02 18:29:04'}
And in index.cfm:
Testing Application Stop
10
Error Message:
Element MYVAR is undefined in APPLICATION.
So, when we are calling ApplicationStop it doesn't affect any session scope variables. Session scope variables remain unchanged and also it doesn't creates a new session. It simply uses the old session scope but reset all application scope variables.
So, if we want to put any object instantiation code in onApplicationStart() then we can reinstantiate that using ApplicationStop().
If someone will ask that why can't we follow simply by calling onApplicationStart() in onRequest() as per our requirements.
Yes, we can do that but it depends on your logic you have implemented in your Application.
If someone doesn't wants to reset all application scope variable then directly call onApplicationStart(). But, if someone wants to reset all application scope variables or using ORM in the Application then ApplicationStop() will work.
Still exploring more on this...
So, I thought use ApplicationStop function which was introduced in ColdFusion-9. Before that I have never used ApplicationStop in any of my previous applications. I had read the documentation that this function basically used in ColdFusion ORM to reload the ORM objects. So, I just did some testing how exactly this function behaves in normal condition.
So, here is my Application.cfc for testing.
Here is index.cfm
If you will notice here in this Application.cfc I just doing file append operation in onApplicationStart(), onSessionStart(), onSessionEnd(), onApplicationEnd() and also inside onRequestEnd() when we want to refresh our application.
When the very first time I run the application I got the following output in file write:
Application started on :- {ts '2013-07-02 18:28:04'}
Session started on :- {ts '2013-07-02 18:28:04'}
And for index.cfm I got the following output:
Testing Application Stop
10
20
Next time I just passed a URL parameter "appReset" so that I can reset the application. Then I got the following output in file write:
Application stop is going to execute on :- {ts '2013-07-02 18:28:49'}
Application ended on :- {ts '2013-07-02 18:28:49'}
And in index.cfm I got the following output:
Testing Application Stop
10
20
So, here we observed that ApplicationStop() executed and then onApplicationStop() executed but onSessionEnd() was not executed.
On third time I just removed the URL parameter for Application reset. Then I got the following output:
In log file:
Application started on :- {ts '2013-07-02 18:29:04'}
And in index.cfm:
Testing Application Stop
10
Error Message:
Element MYVAR is undefined in APPLICATION.
So, when we are calling ApplicationStop it doesn't affect any session scope variables. Session scope variables remain unchanged and also it doesn't creates a new session. It simply uses the old session scope but reset all application scope variables.
So, if we want to put any object instantiation code in onApplicationStart() then we can reinstantiate that using ApplicationStop().
If someone will ask that why can't we follow simply by calling onApplicationStart() in onRequest() as per our requirements.
Yes, we can do that but it depends on your logic you have implemented in your Application.
If someone doesn't wants to reset all application scope variable then directly call onApplicationStart(). But, if someone wants to reset all application scope variables or using ORM in the Application then ApplicationStop() will work.
Still exploring more on this...
Labels:
ColdFusion,
ColdFusion 10,
ColdFusion 9
Friday, November 30, 2012
New Structure Declaration in ColdFusion 10
In ColdFusion 10 a new structure declaration type is introduced. This is very similar to JavaScript Object declaration and it is as follows:
Here we are using colon as separator between key and value rather than '='. Above I have mentioned keys as case sensitive. This means not case sensitive to ColdFusion but other technology like JavaScript.(If we are returning this structure by any AJAX call)
Here we are using colon as separator between key and value rather than '='. Above I have mentioned keys as case sensitive. This means not case sensitive to ColdFusion but other technology like JavaScript.(If we are returning this structure by any AJAX call)
Labels:
ColdFusion 10,
structure
Wednesday, November 28, 2012
Setting Cookie by cfscript in ColdFusion 10
Now a days in ColdFusion coding most of us generally using script version of CF more than tag version. Sometimes we feel upset when we don't get the script version for a particular tag. In such cases we write our own function to use that in script code. CFCOOKIE is one tag which used to set cookie and which doesn't have any script version before ColdFusion 10.
In the above code two ways are quite similar, here we are creating a structure where the key of the structure is exactly same as the attributes of the cfcookie tag. If we are using cfscript to set cookie then we don't need to set name of the cookie in the structure as we usually do for cfcookie.
Also in ColdFusion 10, two new attributes added for setting cookie. These are follows:
preserveCase : Specify if you want to make cookie name case sensitive. This is an optional parameter and default value is "false."
encodeValue : Specify if cookie value should be encoded. This is an optional parameter and default value is "false".
Hope it will help you.
In ColdFusion 10, script version for CFCOOKIE introduced. We can set cookie by cfscript in ColdFusion 10 as follows.
In the above code two ways are quite similar, here we are creating a structure where the key of the structure is exactly same as the attributes of the cfcookie tag. If we are using cfscript to set cookie then we don't need to set name of the cookie in the structure as we usually do for cfcookie.
Also in ColdFusion 10, two new attributes added for setting cookie. These are follows:
preserveCase : Specify if you want to make cookie name case sensitive. This is an optional parameter and default value is "false."
encodeValue : Specify if cookie value should be encoded. This is an optional parameter and default value is "false".
Hope it will help you.
Labels:
cfcookie,
cfscript,
ColdFusion,
ColdFusion 10
Wednesday, November 21, 2012
For-In Loop Over query and struct object
After a long gap now I got some time for my own blog.
Recently I just studied few new functionality which has been added in ColdFusion 10. For-in loop one of the functionality liked.
Lets take a look into the following code to use for-in loop for looping over any structure or any query object.
Happy Coding. Lets wait for some new interesting things in ColdFusion 10.
Recently I just studied few new functionality which has been added in ColdFusion 10. For-in loop one of the functionality liked.
Lets take a look into the following code to use for-in loop for looping over any structure or any query object.
<cfscript>
//Create an Query Object
qryEmployeeList = queryNew("empID, firstName, lastName", "BigInt, VarChar, VarChar");
queryAddRow(qryEmployeeList, 2);
querySetCell(qryEmployeeList, "empID", 1, 1);
querySetCell(qryEmployeeList, "firstName", "Sachin", 1);
querySetCell(qryEmployeeList, "lastName", "Tendulkar", 1);
querySetCell(qryEmployeeList, "empID", 2, 2);
querySetCell(qryEmployeeList, "firstName", "Rahul", 2);
querySetCell(qryEmployeeList, "lastName", "Dravid", 2);
//Create Struct
strEmployeeInfo = structNew();
strEmployeeInfo['empID'] = "3";
strEmployeeInfo['firstName'] = "Saurav";
strEmployeeInfo['lastName'] = "Ganguly";
//Loop Over Query Object using for in
for( employee in qryEmployeeList) {
WriteOutPut(employee.empID & " : " & employee.firstName & " " & employee.lastName & "<br/>");
}
//Loop Over struct Object using for in
for(strfieldName in strEmployeeInfo) {
WriteOutPut(strfieldName & " : " & structFind(strEmployeeInfo, strfieldName) & "<br/>");
}
</cfscript>
Happy Coding. Lets wait for some new interesting things in ColdFusion 10.
Labels:
ColdFusion,
ColdFusion 10,
for-in loop
Subscribe to:
Posts (Atom)






























