You need to sign in to do that
Don't have an account?
deter dangler
Variable set from VF page is not available for a controller method
I am setting a Controller extension variable from VF page using apex action Function in the call back of the remote action method and then trying to read this value from another method in the controller extension.
Here is the code:
Controller Extension:
My VisualForce Page:
Here is the code:
Controller Extension:
global with sharing class MyController { public String variableOne{get;set;} public MyController(ApexPages.StandardController stdController) { } public PageReference methodTwo() { System.debug('Variable value from methodTwo is '+ variableOne); return null; } public PageReference methodThree() { System.debug('variable value from methodThree is '+ variableOne); return null; } @RemoteAction global static String methodOne(String s1){ return s1+'123'; } }
My VisualForce Page:
<apex:page standardController="Account" extensions="MyController"> <c:ScriptsComponent id="scmp"/> <script type="text/javascript"> var records; function functionOne(){ console.log('Entered the functionOne method'); Visualforce.remoting.Manager.invokeAction( '{!$RemoteAction.MyController.methodOne}', 'Andrew', function(result,event){ console.log('result->' + JSON.stringify(result)); records = result; if(event.status){ console.log('result we got back from controller is '+records); setValueJS(records); methodOneJS(); } }); } </script> <div> <p onClick="functionOne(); return false;">Click Here</p> <apex:form > <apex:actionFunction name="setValueJS" action="{!methodTwo}"> <apex:param name="parm1" assignTo="{!variableOne}" value=""></apex:param> </apex:actionFunction> <apex:actionFunction name="methodOneJS" action="{!methodThree}"> </apex:actionFunction> </apex:form> </div> </apex:page>
- I never see the debug line in methodTwo priting.
- Debug line in methodThree always says that the variable value is null
- This might be javascript or jquery but the page reloads after i clicking on the p element
(1) Invoke them all server side from a single action method - I'd always recommend this as its much more straightforward to understand.
(2) Use the rerender tags to turn the requests into Ajax and add oncomplete handlers that invoke the next function in the chain. These can be hard to debug.
All Answers
(1) Invoke them all server side from a single action method - I'd always recommend this as its much more straightforward to understand.
(2) Use the rerender tags to turn the requests into Ajax and add oncomplete handlers that invoke the next function in the chain. These can be hard to debug.
Why doesn't Javascript wait until the setValueJS method is executed successfully before executing the methodOneJS?
Is it because these are actionFunctions??
Thanks again for your time in looking into it.