• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 367
  • Last Modified:

Converting coldfusion code to jsp code

Hello Experts
This is regarding popups and a part of my implementation in JSP page has to do with something similar in lines to this piece of code, originally implemented in coldfusion. Can anyone please advice on what this piece of code is trying to do and how can i implement the same in jsp. Thanks.

(Just can't understand what the 3 stored procs are doing. Can't see where the user chose Supress Popup. And also, why the cookie named suppresspopup is set to expire NOW??)
<!--- suppress popup --->
<CFIF IsDefined("cookie.SuppressPopup")>
	<cfcookie name="SuppressPopup" expires="NOW" domain="blahblah" path="/">
  <cfset cEnablePopUps = "N">
<cfelse>
		<!--- is popups enabled? --->
    <CFSTOREDPROC PROCEDURE="pr_GetSystemData" DATASOURCE="#DBSOURCE#"
    	USERNAME="#DBUSER#" PASSWORD="#DBPASSWORD#" RETURNCODE="Yes">
    	<CFPROCPARAM TYPE="In" CFSQLTYPE="CF_SQL_VARCHAR" DBVARNAME="@KeyName"
    		VALUE="PopUpsEnabled" MAXLENGTH="100" NULL="No">
    	<CFPROCPARAM TYPE="In" CFSQLTYPE="CF_SQL_VARCHAR" DBVARNAME="@DefaultValue"
    		VALUE="Y" MAXLENGTH="1024" NULL="No">
    	<CFPROCPARAM TYPE="Out" CFSQLTYPE="CF_SQL_VARCHAR" DBVARNAME="@DefaultValue"
    		VARIABLE="cEnablePopUps" MAXLENGTH="1024" NULL="No">
    </CFSTOREDPROC>
 
    <!--- if enabled, check if its enabled for each of the following conditions --->
    <cfif cEnablePopUps eq "Y">
        <cfif (Len(Trim(request.readerContext.getTempSessionData("VisitorIID", ""))) gt 0)>
            <CFSTOREDPROC PROCEDURE="pr_GetSystemData" DATASOURCE="#DBSOURCE#"
            	USERNAME="#DBUSER#" PASSWORD="#DBPASSWORD#" RETURNCODE="Yes">
            	<CFPROCPARAM TYPE="In" CFSQLTYPE="CF_SQL_VARCHAR" DBVARNAME="@KeyName"
            		VALUE="cEnableSurvey1PopUps" MAXLENGTH="100" NULL="No">
            	<CFPROCPARAM TYPE="In" CFSQLTYPE="CF_SQL_VARCHAR" DBVARNAME="@DefaultValue"
            		VALUE="Y" MAXLENGTH="1024" NULL="No">
            	<CFPROCPARAM TYPE="Out" CFSQLTYPE="CF_SQL_VARCHAR" DBVARNAME="@DefaultValue"
            		VARIABLE="cEnableSurvey1PopUps" MAXLENGTH="1024" NULL="No">
            </CFSTOREDPROC>
 
            <cfif cEnableSurvey1PopUps eq "Y">
            	<cfset sExitPopLoc = "/someurl.cfm">
            </cfif>
 
        <cfelseif ( Trim(request.readerContext.getContextData("sPromoCode", "")) eq "SPECIALTVOFFER" OR
          				Trim(request.readerContext.getContextData("sPromoCode", "")) eq "SPECIALTVOFFER_SALE")>
            <CFSTOREDPROC PROCEDURE="pr_GetSystemData" DATASOURCE="#DBSOURCE#" USERNAME="#DBUSER#"
            	PASSWORD="#DBPASSWORD#" RETURNCODE="Yes">
            	<CFPROCPARAM TYPE="In" CFSQLTYPE="CF_SQL_VARCHAR" DBVARNAME="@KeyName"
            		VALUE="cEnableSurvey2PopUps" MAXLENGTH="100" NULL="No">
            	<CFPROCPARAM TYPE="In" CFSQLTYPE="CF_SQL_VARCHAR" DBVARNAME="@DefaultValue"
            		VALUE="Y" MAXLENGTH="1024" NULL="No">
            	<CFPROCPARAM TYPE="Out" CFSQLTYPE="CF_SQL_VARCHAR" DBVARNAME="@DefaultValue"
            		VARIABLE="cEnableSurvey2PopUps" MAXLENGTH="1024" NULL="No">
            </CFSTOREDPROC>
 
            <cfif cEnableSurvey2PopUps eq "Y">
            	<cfset sExitPopLoc = "/someurl.cfm">
            </cfif>
 
        <cfelse>
            <CFSTOREDPROC PROCEDURE="pr_GetSystemData" DATASOURCE="#DBSOURCE#"
            	USERNAME="#DBUSER#" PASSWORD="#DBPASSWORD#" RETURNCODE="Yes">
            	<CFPROCPARAM TYPE="In" CFSQLTYPE="CF_SQL_VARCHAR" DBVARNAME="@KeyName"
            		VALUE="cEnableSurvey3PopUps" MAXLENGTH="100" NULL="No">
            	<CFPROCPARAM TYPE="In" CFSQLTYPE="CF_SQL_VARCHAR" DBVARNAME="@DefaultValue"
            		VALUE="Y" MAXLENGTH="1024" NULL="No">
            	<CFPROCPARAM TYPE="Out" CFSQLTYPE="CF_SQL_VARCHAR" DBVARNAME="@DefaultValue"
            		VARIABLE="cEnableSurvey3PopUps" MAXLENGTH="1024" NULL="No">
            </CFSTOREDPROC>
 
            <cfif cEnableSurvey3PopUps eq "Y">
            	<cfset sExitPopLoc = "/someurl.cfm">
            </cfif>
 
        </cfif>
		</cfif>
</cfif>

Open in new window

0
AnithaE
Asked:
AnithaE
  • 3
  • 2
1 Solution
 
mrcoffee365Commented:
I suggest you make a flow chart of the actions in the code snippet you've posted - that will help you figure out what you need to investigate further.

 It's checking to see if there's a cookie named SuppressPopup.
If one exists:
* delete the SuppressPopup cookie by setting the expires="NOW" value
* set the cEnablePopUps global (?) variable to N for No, presumably

If one does not exist:
* Run stored procedure pr_GetSystemData
  - Check value of cEnablePopUps  now.  If Y:
      + If Len(Trim(request.readerContext.getTempSessionData("VisitorIID", ""))) gt 0, call pr_GetSystemData
        this time to get cEnableSurvey1PopUps
        * if cEnableSurvey1PopUps = Y, set the sExitPopLoc value to a URL
     + else if some value exists for sPromoCode, call pr_GetSystemData
        this time to get cEnableSurvey2PopUps
        * if cEnableSurvey2PopUps = Y, set the sExitPopLoc value to a URL
     + else
        call pr_GetSystemData to get cEnableSurvey3PopUps
       * if cEnableSurvey3PopUps = Y, set the sExitPopLoc value to a URL

There are many tutorials for ColdFusion on the Web.  You can google for cfcookie, cfm tutorials, etc.

In order to understand what the 3 stored procedures are doing, you'll have to look at the code for them.  Are you using a SQL Server db?  If so, look for the stored procedures in the db by the names given in this CFM code, and you'll be able to tell what they are doing.
0
 
AnithaEAuthor Commented:
mrcoffee365, can't tell how much i'm thankful to you. The BEST part of your solution(I would rather say SERVICE to the community) is- You are giving hints as to how we can approach a given task systematically and you are showing you are thinking and arriving at a solution. That is really Wonderful.

NOW, I have everything together for this exit popup functionality and it works beautifully- for Anonymous users/Enable Popups is YES/Leaves the site. The only place it breaks is- the exit popup shows up on a REFRESH/Back button on Browser even though it is an Internal Link.
I have 2 javascript functions - window.onload=initpage and window.onunload=leavingsite. In initpage()- i'm marking all the internal links (document.links[i].onclick=insite;) and form submissions (document.forms[i].onsubmit=insite;) to LEAVING FALSE and in window.onunload=leavingsite, i'm calling OPENEXITPOPUP if LEAVING is True.
What could i do for Exit Popup not to show on Refresh and Back buttons -

Thank you all Experts.


0
 
mrcoffee365Commented:
Thanks for the thanks!  It's always nice to hear.

It sounds as if you've made great progress.  The problem of OnUnload and the Refresh and Back buttons is a common one.  There aren't any perfect solutions, but there are some reasonable workarounds.

For Refresh and Back, the request does not go back to the Web server, so you can't handle it by actions on the server side.  It's the Javascript you already put on the page that is being re-executed.

So, a common Javascript solution is to either set a Javascript variable in the page or set a value in a special cookie just for detecting this situation.  This page has a good description of the cookie solution (which I think is a better one):
http://www.tedpavlic.com/post_detect_refresh_with_javascript.php

The cookie holds the current page name and the datetime stamp.  OnLoad (not Unload) creates the cookie.  OnUnload checks to see if the cookie exists, and if it's too close to the datetime stamp, does not execute your exit popup.

So once you work out the desired Javascript behavior with a plain HTML page, you'll know how to change the Javascript you generate from your CFM page.
0
 
AnithaEAuthor Commented:
Very much indebted to you. Btw, I'm a Java/J2ee person. I had to convert some existing coldfusion code into a java solution with some additional scenarios. Have a great day!
0
 
mrcoffee365Commented:
Glad to help.  Good luck.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now