home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 February / CHIPCD_02_2002.iso / Internet / Macromedia ColdFusion Server 5 / coldfusion-50-win-us.exe / data1.cab / Examples / CFDOCS / snippets / cflock.cfm < prev    next >
Encoding:
Text File  |  2001-06-13  |  4.6 KB  |  139 lines

  1.  
  2. <!------------------------------------------------------------- 
  3.     This example shows how CFLOCK can be used to guarantee the
  4.     consistency of data updates to variables in the Application, 
  5.     Server, and Session scopes.
  6.     You should copy the following code into an Application.cfm
  7.     file in the wwwroot directory. 
  8. --------------------------------------------------------------->
  9.     <HTML>
  10.     <HEAD>
  11.         <title>Define Session and Application Variables</title>
  12.     </HEAD>
  13.     
  14.     <BASEFONT FACE="Arial, Helvetica" SIZE=2>
  15.     <BODY  bgcolor="#FFFFD5">
  16.     
  17.     <H3>CFAPPLICATION Example</H3>
  18.     
  19.     <P>CFAPPLICATION defines scoping for a ColdFusion application and 
  20.     enables or disables the storing of application and/or session
  21.     variables. This tag is placed in a special file called
  22.     Application.cfm that is run before any other CF template in a
  23.     directory where the Application.cfm file appears.
  24.     <!------------------------------------------------------------- 
  25.     <CFAPPLICATION NAME="ETurtle" SESSIONTIMEOUT=#CreateTimeSpan(0, 0, 
  26.       0, 60)# SESSIONMANAGEMENT="yes">
  27.     ---------------------------------------------------------------> 
  28.       
  29.     <!------------------------------------------------------------- 
  30.     Initialize the session and application variables that will be 
  31.     used by E-Turtleneck. Use the session scope for the session 
  32.     variables.
  33.     ---------------------------------------------------------------> 
  34.     <!----------------------------------------------------------------
  35.     <CFLOCK SCOPE="Session" TIMEOUT="30" TYPE="Exclusive">
  36.         <CFIF NOT IsDefined("session.size")>
  37.             <CFSET session.size = "">
  38.         </CFIF>
  39.         <CFIF NOT IsDefined("session.color")>
  40.             <CFSET session.color = "">
  41.         </CFIF>
  42.     </CFLOCK>
  43.     ------------------------------------------------------------------->
  44.     <!---------------------------------------------------------------- 
  45.     Use the application scope for the application variable. This
  46.     variable keeps track of the total number of turtlenecks sold. 
  47.     ------------------------------------------------------------------->
  48.     <!---------------------------------------------------------------- 
  49.     <CFLOCK SCOPE="Application" TIMEOUT="30" TYPE="Exclusive">
  50.         <CFIF NOT IsDefined("application.number")>
  51.             <CFSET application.number = 1>
  52.         </CFIF>
  53.     </CFLOCK>
  54.     <CFLOCK SCOPE="Application" TIMEOUT="30" TYPE="ReadOnly">
  55.         <CFOUTPUT>
  56.         E-Turtleneck is proud to say that we have sold #application.number#
  57.         <CFIF #application.number# NEQ 1>
  58.         turtlenecks 
  59.         <CFELSE>
  60.         turtleneck
  61.         </CFIF>
  62.         to date.
  63.         </CFOUTPUT>
  64.     </CFLOCK> 
  65. ------------------------------------------------------------------->
  66. <!--- End of Application.cfm --->
  67.  
  68. <HEAD>
  69. <TITLE>
  70. CFLOCK Example
  71. </TITLE>
  72. </HEAD>
  73.  
  74. <BASEFONT FACE="Arial, Helvetica" SIZE=2>
  75. <BODY  bgcolor="#FFFFD5">
  76.  
  77. <H3>CFLOCK Example</H3>
  78.  
  79. <CFIF IsDefined("form.submit")>
  80.     <CFOUTPUT>
  81.         Thank you for shopping E-Turtleneck. Today you have
  82.         chosen a turtleneck in size <b>#form.size#</b> and in the color
  83.         <b>#form.color#</b>. 
  84.     </CFOUTPUT>
  85.     
  86.     <!----------------------------------------------------------------- 
  87.      Lock session variables to assign form values to them. 
  88.     -------------------------------------------------------------------> 
  89.     <CFLOCK SCOPE="Session" TIMEOUT="30" TYPE="Exclusive">
  90.         <CFPARAM NAME=session.size Default=#form.size#>
  91.         <CFPARAM NAME=session.color Default=#form.color#>
  92.     </CFLOCK>
  93.     <!------------------------------------------------------------------ 
  94.     Lock application variable application.number to find the total number 
  95.     of turtlenecks sold. 
  96.     -------------------------------------------------------------------> 
  97.     <CFLOCK SCOPE="Application" TIMEOUT="30" TYPE="Exclusive">
  98.         <CFSET application.number = application.number + 1>
  99.     </CFLOCK>
  100.     
  101. <CFELSE><!--- Show the form only if it has not been submitted. --->
  102.  
  103. <FORM ACTION="cflock.cfm" METHOD="POST">
  104.  
  105. <P>Congratulations! You have just selected the longest wearing, most comfortable turtleneck in the world. Please indicate the color and size that you wish to buy.</P> 
  106. <table cellspacing="2" cellpadding="2" border="0">
  107. <tr>
  108.     <td>Select a color.</td>
  109.     <td><SELECT TYPE="Text" NAME="color">
  110.         <OPTION>red
  111.         <OPTION>white
  112.         <OPTION>blue
  113.         <OPTION>turquoise
  114.         <OPTION>black
  115.         <OPTION>forest green
  116.         </SELECT>
  117.     </td>
  118. </tr>
  119. <tr>
  120.     <td>Select a size.</td>
  121.     <td><SELECT TYPE="Text" NAME="size" >
  122.         <OPTION>XXsmall
  123.         <OPTION>Xsmall
  124.         <OPTION>small
  125.         <OPTION>medium
  126.         <OPTION>large
  127.         <OPTION>Xlarge
  128.         </SELECT>
  129.     </td>
  130. </tr>
  131. <tr>
  132.     <td>Press Submit when you are finished making your selection.</td>
  133.     <td><INPUT TYPE="Submit" NAME="submit" VALUE="Submit"> 
  134.     </td>
  135. </tr>
  136. </table>
  137. </FORM>
  138. </CFIF>
  139. </HTML>