Alpha DevCon 2018
Results 1 to 3 of 3

Thread: Variables lost after submit

  1. #1
    "Certified" Alphaholic
    Real Name
    Frank Bicknell
    Join Date
    Feb 2010
    Location
    39.1915° N, 84.4348° W
    Posts
    2,441

    Default Variables lost after submit

    I have a grid. In the OnSearchPartFilterCompute server side event I am setting a variable using the e.rtc pointer.
    I am accessing the e.rtc pointer variable in the OnSummarySectionRender server side event of the grid.
    When the grid is first initialized and the search data entered and search button is pressed the grid displays the proper records.
    I can edit the records as desired.
    When I submit or cancel changes to the grid I get an error message e.rtc.endDate not found.


    I have tried using the e._state pointer as well, however, after the submit it is gone.


    Basically I am taking an ending date and using it in the OnSummarySectionRender as a mySql query filter argument.
    Also this grid is called from a UX with a link on account no.
    It all works OK in working preview.

    Can anyone shed light on this. I feel like this should be very basic and should work as I have it coded.
    Last edited by frankbicknell; 12-28-2017 at 09:19 PM.
    Win 10 64 Development, Win 7 64 WAS 11-1, 2, Win 10 64 AA-1,2, MySql, dbForge Studio The Best MySQL GUI Tool IMHO. http://www.devart.com/dbforge/mysql/studio/

  2. #2
    Member
    Real Name
    Rich Fulham
    Join Date
    May 2011
    Location
    Portland, OR
    Posts
    835

    Default Re: Variables lost after submit

    1) For the e.rtc variables in a Grid, I just re-init them in the onGridExecute server side event. That event is supposed to run all the time before any other server event runs. The e.rtc variables do not stick around between callbacks, so they have to be constantly initialized. In Working Preview they might stick around because AA handles global memory quite a bit differently in WP mode then when in server mode. If the e.rtc variable is something simple that does not involve the DB lookups, I just initialize it every time "onGridExecute" runs. If the variable(s) involve looking stuff up in the DB then I conditionally initialize them based on need. It was rather tedious figuring out the code to conditionally initialize them. You would need to see what works for you. I have taken my code from a working Grid and cleaned it up a little and provided it below, as an example. Sorry, if I introduced any errors into the code, but I think you will get the idea of it.

    2) My sample below also includes the server side stuff needed if you want to use "state" variables in a Grid.

    Code:
    function OnGridExecute as v (e as p)
    '-- Setting up e.rtc vars in a Grid.   e.rtc vars do not stick around between callbacks.  
    '-- So, they need to be initialized every time they will be used in a subsequent server-side event durring the current initialization or callback.
    
    e.rtc.currJDate = jDate( date() ) '-- Simple var, always initialized
    
    '-- Sometimes when AA calls this function, 'onGridExecute', it might not be planning on calling any of your Server-Side events that need your e.rtc vars.
    '-- The "e.rv.__FormAction" variable can be used to identify why AA called this function.
    '-- It is a matter of trial and error while running under server mode (not w/p mode) of when it is safe to not bother initializing the e.rtc vars.
    '-- But, you have to run under W/P mode to figure out what the possible values of "e.rv.__FormAction". Unless, you perhaps send back Javascript
    '-- to "alert" the values discovered in the "e.rv.__FormAction" field.
    
    '-- You have to check what values of the following variable Alpha sends into this procedure.  
    '-- I have only listed the values that I discovered AA used for my Grid AND where it was NOT necessary to init my e.rtc vars.
    '-- Your grid will likely have more values than mine, as my Grid does not have all possible Grid features turned on. 
    '-- It could be that you need to initialize your e.rtc vars during some of these events.
    
    if variable_exists("e.rv.__FormAction")
    	dim act as c = new ""
    	act = e.rv.__FormAction
    	select 
    		'-- These are the events where it was not neccessary for me to init e.rtc vars because no subsequent server event needed them.
    		case act = "PageNavigate"
    			end
    		case act = "SetRowsPerPage"
    			end
    		case act = "refreshRow"
    			end
    		case act = "saveGridData"
    			end
    		case act = "submit"
    			end
    		case act = "GenericAjaxCallback"
    			end
    	end select			
    end if
    
    if .not. variable_exists("e.rtc")
    	dim e.rtc as P '-- Sanity check
    end if
    
    '-- If you want to preserve the e.rtc variables between callbacks, you can do it by storing them in 'state' variables.
    '-- But it gets tricky and you have to be careful about refering to the state variables.  
    '-- If the state variables exist in a subsequent callback, you will find them inside "e.rv.__si2".
    '-- If they don't exist yet, then you have to compute them and put them into "e._state".
    '-- If you intend to use the state variables client-side then you have to code your Javascript to safely bailout 
    '-- when the state vars do not exist yet.  Unless the problem has been fixed, AA does not give enough priority to 
    '-- initializing state variables on the client-side. So, if you use Grid state vars client side in an event then it 
    '-- might be that those vars have not been initized yet. You don't want the JS code to stop running because of an
    '-- undefined error, so make sure you check for state var existence before using them in expressions.  There are times
    '-- where the A5 JS library will call a client-side event multiple times.  I'm not sure exactly why.  But counting on
    '-- this fact, one can assume the library will get around to calling the event a second time and the state vars'
    '-- will have been initized by that time.
    
    
    '-- Restoring a pointer variable from state to e.rtc variable...
    dim myStateExists as L
    myStateExists = .f.
    if variable_exists("e.rv")
    	if variable_exists("e.rv.__si2")
    		if variable_exists("e.rv.__si2.MyStateVarPtr")
    			myStateExists = .t.
    			delete e.rtc.MyStateVarPtr  '-- Sanity check
    			dim e.rtc.MyStateVarPtr as P
    			PROPERTY_RECURSE_ASSIGN(e.rtc.MyStateVarPtr, e.rv.__si2.MyStateVarPtr)
    		end if
    	end if
    end if	
    if myStateExists = .f.
    	' Running the component for the first time or this type of callback did not set up the state variable
    	delete e.rtc.MyStateVarPtr	! Sanity Check
    	dim e.rtc.MyStateVarPtr as P
    	Init_my_rtc_vars(e, e.rtc.MyStateVarPtr) 
    	'-- Copy e.rtc vars to state object for: 1) client-side use, and 2) won't have to recompute them on callbacks
    	if .not. variable_exists("e._state")
    		dim e._state as P '-- Create the state vars in this object, so Alpha will populate the real state var that is passed down to browser.
    	end if
    	delete e._state.MyStateVarPtr		! Sanity check
    	dim e._state.MyStateVarPtr as P
    	PROPERTY_RECURSE_ASSIGN(e._state.MyStateVarPtr, e.rtc.MyStateVarPtr)	
    end if
    
    '-- Put any follow-up code here, that you need.
    
    end function

  3. #3
    "Certified" Alphaholic
    Real Name
    Frank Bicknell
    Join Date
    Feb 2010
    Location
    39.1915° N, 84.4348° W
    Posts
    2,441

    Default Re: Variables lost after submit

    Thanks Rich. Miraculously it started working OK. I hate when that happens because I am afraid it may come back.
    Win 10 64 Development, Win 7 64 WAS 11-1, 2, Win 10 64 AA-1,2, MySql, dbForge Studio The Best MySQL GUI Tool IMHO. http://www.devart.com/dbforge/mysql/studio/

Similar Threads

  1. Getting one button to submit, and the other to submit and reset.
    By JackByrne in forum Mobile & Browser Applications
    Replies: 1
    Last Post: 10-09-2014, 09:29 PM
  2. How to submit linked child grid upon parent submit?
    By WindForce in forum Application Server Version 11 - Web/Browser Applications
    Replies: 3
    Last Post: 12-28-2011, 08:09 AM
  3. How to condense multiple submit buttons to a single submit button
    By kthibeault1965 in forum Application Server Version 9 - Web/Browser Applications
    Replies: 5
    Last Post: 11-20-2008, 08:02 AM
  4. Submit on lost password page
    By Bill Parker in forum Application Server Version 8
    Replies: 0
    Last Post: 05-13-2008, 11:24 PM
  5. lost the submit button
    By Duane Pederson in forum Web Application Server v6
    Replies: 1
    Last Post: 07-22-2005, 02:58 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •