I am working on a Visualforce page that contains some javascript. The page has a controller extension. For the past several days I have been researching how to pass the value of a javascript variable value in my VF page to the Apex Controller, where I need to use that value to do some things. Nothing I have tried is working even though I have seen some similar examples of code that should do what I am trying to do. Please help because I am going bonkers.
I have a javascript variable in my visualforce page called inLightning. When the VF page loads, inLightning = true or false depending on whether the current user is in the Lightning UI or the Classic UI. There is other javascript in the VF page that returns this value and populates into my inLightning variable. I know this part is working. I need to tell my Apex Controller whether the current user is in Lightning or Classic, so I am trying to pass the value of inLightning to my controller like so:
I have a javascript function like this where I am passing the value of my inLightning variable. The variable already has a value of true or false by the time this function gets called.
function getValue(inLightning)
{
passValue(inLightning);
}
Now in my visual force page, I am using an apex:actionFunction with an apex:param to pass this to my controller like so:
<apex:form>
<apex:actionFunction name="passValue" action="{!UIValue}" immediate="true">
<apex:param> id="LightningParam" name="LightningParam" value="" />
</apex:actionFunction>
</apex:form>
In my controller extension, I have included a little method called UIValue like so:
public void UIValue()
{
String value = ApexPages.currentPage().getParameters().get('LightningParam');
system.debug('string value is '+value);
}
Whenever I load the visualforce page, the action function doesn't work and the controller UIValue method doesn't work. Once the page loads and I look at my debug log, my system.debug statement above isn't in my log. Apparently my UIValue method isn't running.
I don't know what to do next. I don't want to have to do a click event or something like that to make this work. When the visualforce page loads, I want the code to run that will pass the value of my inLightning javascript variable to my controller. Any suggestions are appreciated.