• Luca Benedettini 25
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi,
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 a variable "Value" 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="{!Value}" />

apex controller:
public List<String> values {get;set;}
private String Value = 'no';
   public void setValue(String n) {
        Value = n;
   System.debug('Set Passed in Value: '+ Value);     
    }
    public String getValue() {
   System.debug('Get Passed in Value: '+ Value);
        return Value;
       
    }
public void MyConMethod() {
        system.debug('Start');             
       convertStrToList(Value);
        
    }
 
    public void convertStrToList(String str) {
    String[] listToReturn = new List<String>();
    if(String.isNotBlank(str)) {
        for(String eachStr : str.split(',')) {
            listToReturn.add(eachStr);
        }
    }
    system.debug(listToReturn);
    }
The debug logs shows the message: Passed in value: null
I really don't understand what's going wrong. Why Value doesn't contain the array in d? Help me please
 
Hi,
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 a variable "Value" 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="{!Value}" />

apex controller:
public List<String> values {get;set;}
private String Value = 'no';
   public void setValue(String n) {
        Value = n;
   System.debug('Set Passed in Value: '+ Value);     
    }
    public String getValue() {
   System.debug('Get Passed in Value: '+ Value);
        return Value;
       
    }
public void MyConMethod() {
        system.debug('Start');             
       convertStrToList(Value);
        
    }
 
    public void convertStrToList(String str) {
    String[] listToReturn = new List<String>();
    if(String.isNotBlank(str)) {
        for(String eachStr : str.split(',')) {
            listToReturn.add(eachStr);
        }
    }
    system.debug(listToReturn);
    }
The debug logs shows the message: Passed in value: null
I really don't understand what's going wrong. Why Value doesn't contain the array in d? Help me please