[SalesForce] Apex param is giving NULL value

I am assigning value of one Input field to two variables-'UserResponsibleA and UserResponsibleB through <apex:param> and both are returning NULL values to controller. Here Responsible__c is a User Lookup field. Can you please check where is the problem.Any help will be highly appreciated.

VF Page:

function callActionMethod(){
var txtVal1 = document.getElementById("{!$Component.frm.val1}").value;
var txtVal2 = document.getElementById("{!$Component.frm.val2}").value;
echo(txtVal1,txtVal2 );
}

<apex:form id="frm">
    <apex:commandButton value="Save" action="{!saveResponsible}" onclick="callActionMethod()"/>
        <apex:inputField value="{!Responsible__c.Responsible__c}"  id="val1"/>
        <apex:inputField value="{!Responsible__c.Responsible__c}"  id="val2"/>
        <apex:actionFunction action="{!saveResponsible}" name="echo" reRender="">
            <apex:param name="UserResponsibleA" value="{!UserResponsibleA}" />
            <apex:param name="UserResponsibleB"  value="{!UserResponsibleB}" />           
        </apex:actionFunction>
</apex:form> 

Class:

 public with sharing class WorkPlanAddResponsibleVFPExtension{  
    public Id UserResponsibleA{get;set;}  
    public Id UserResponsibleB{get;set;}  
    public WorkPlanAddResponsibleVFPExtension(ApexPages.Standardcontroller std){  
        UserResponsibleList = new List<Id>();  
    }  
    public void saveResponsible(){  
        UserResponsibleA = ApexPages.currentPage().getParameters().get('UserResponsibleA');
        UserResponsibleB = ApexPages.currentPage().getParameters().get('UserResponsibleB');
        System.Debug('@@UserResponsibleA'+UserResponsibleA);  
        System.Debug('@@UserResponsibleB'+UserResponsibleB);       
    }
  }     

Best Answer

There's a quirk with <apex:actionFunction> in that it won't pass any parameters (i.e. the actual generated javascript function takes no parameters) unless you include a rerender attribute. That can be blank, so this might do the trick:

<apex:actionFunction action="{!saveResponsible}" name="echo" rerender="">

That said, I've rarely had luck using assignTo and tend to fall back on retrieving the parameters directly in code, for example:

String firstParam = ApexPages.CurrentPage().GetParameters().Get('firstParam');
Related Topic