I have a little problem but I'm not able to find a solution.I'm trying to pass an array variable "d" from javascript to List variable "values" in the apex controller. Here my code:
javascript:
function setVal(param){
param =param.replace("[","");
param =param.replace("]","");
var mylist = new Array()
mylist = param.split(',');
alert(mylist);
var d =new Array();
for( var i = 0; i < mylist.length; i++ ){
var appoggio = mylist[i].trim();
var strAppoggio = document.getElementById( appoggio ).innerHTML;
strAppoggio = strAppoggio.substring(strAppoggio.lastIndexOf("*") + 1, strAppoggio.lastIndexOf("+"));
d.push(strAppoggio);
}
afConMethod(d.join());
alert('dToString: ' + dToString);
}
visualforce:
<apex:commandButton value="Get" onclick="setVal('{!firstrow}');" reRender="output"/>
<apex:actionFunction name="afConMethod" action="{!MyConMethod}" >
<apex:param value="" name="theValue" assignTo="{!theValue}" />
apex controller:
public String theValue {get;set;}
public List<String> values {get;set;}
//controller
public ApexPages.StandardController stdController;
public excelPageController(ApexPages.StandardController stdcontroller) {
//this.stdController = stdController;
oppId =ApexPages.currentPage().getParameters().get('ID');//Current opportunity ID;
}
system.debug('Start');
//theValue=Apexpages.currentPage().getParameters().get('theValue');
system.debug('Passed in theValue: '+ theValue);
values = convertStrToList(theValue);
system.debug('Passed in value2: '+ values);
}
public String[] convertStrToList(String str) {
String[] listToReturn = new List<String>();
if(String.isNotBlank(str)) {
for(String eachStr : str.split(',')) {
listToReturn.add(eachStr);
}
}
return listToReturn;
}
The debug logs shows the message: Passed in value: null
I really don't understand what's going wrong.
d.toString()
when you call your controller method in javascript ? – SF_user Oct 27 '16 at 15:08