You need to sign in to do that
Don't have an account?
Apoorva Sharma
Passing javascript array to apex class
Hi,
I want to pass javascript array to apex class. my code is:
VF Page:
<apex:page Controller="MyController" id="page" >
<apex:form >
<apex:commandButton value="Save" action="{!say}"/>
<apex:inputHidden id="hiddenParamValueFromJavaScript" value="{!ParamValueFromJavaScript}" />
<apex:dynamicComponent componentValue="{!form}" id="dynamic" />
<script type="text/javascript">
List=[val1,val2,val3];
var ctrl = document.querySelector('[id$="hiddenParamValueFromJavaScript"]');
ctrl.value = List;
</script>
</apex:form>
</apex:page>
Apex Class:
public class MyController
{
public String form { get; set; }
public MyController() {
}
public MyController(ApexPages.StandardController controller)
{
}
public String[] ParamValueFromJavaScript {get;set;}
public void say(){
system.debug(ParamValueFromJavaScript);
}
}
But in debug log i am not able to see the debug statement. I am getting the following error:
Invalid conversion from runtime type String to LIST<String>
Can someone please help me with this??
I want to pass javascript array to apex class. my code is:
VF Page:
<apex:page Controller="MyController" id="page" >
<apex:form >
<apex:commandButton value="Save" action="{!say}"/>
<apex:inputHidden id="hiddenParamValueFromJavaScript" value="{!ParamValueFromJavaScript}" />
<apex:dynamicComponent componentValue="{!form}" id="dynamic" />
<script type="text/javascript">
List=[val1,val2,val3];
var ctrl = document.querySelector('[id$="hiddenParamValueFromJavaScript"]');
ctrl.value = List;
</script>
</apex:form>
</apex:page>
Apex Class:
public class MyController
{
public String form { get; set; }
public MyController() {
}
public MyController(ApexPages.StandardController controller)
{
}
public String[] ParamValueFromJavaScript {get;set;}
public void say(){
system.debug(ParamValueFromJavaScript);
}
}
But in debug log i am not able to see the debug statement. I am getting the following error:
Invalid conversion from runtime type String to LIST<String>
Can someone please help me with this??
BHinners
It looks like you have an array of strings in JavaScript that you are trying to pass into a string variable in Apex. So I think you should change your apex variable to List<String>