function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
dai tran 6dai tran 6 

Why actionFuntion can't send parameter?

Visual Page:
<li><a href="" onclick="getProduct('{!fa.Family}'); return false;">{!fa.Family}</a></li>
<apex:actionFunction action="{!searchByFamily}" name="getProductFamily" >
           <apex:param name="family" value="" assignTo="{!family}" />
 </apex:actionFunction>
  <script>
  function getProduct(family)
         {
               getProductFamily(family);
         }
    </script>

Controller:
public string family { get;set;}
 public void searchByFamily(){ 
         System.debug(family);
            string searchquery='select ProductCode,Name,ImageName__c,(Select UnitPrice,Pricebook2.Name From PricebookEntries where IsActive=True)  from Product2 where Family=:family '; 
            MyProducts= Database.query(searchquery); 
     }

Log debug:
04:27:26.0 (32330563)|USER_DEBUG|[98]|DEBUG|null

Why actionFuntion can't send parameter?
Best Answer chosen by dai tran 6
Mohd  RaisMohd Rais
Hi Dai,
Yes, You can use apex:actionFunction.
In visualforce, there is a method for passing parameters from visualforce page to controller using javascript and actionFunction. Here is the example;
/*JavaScript*/
<script type="text/javascript">
function doSave(date) {
    paraFunction(document.getElementById(date).value);
}
</script>

/*Action Function*/
<apex:actionFunction name="paraFunction" action="{!saveInterviewDate}" rerender="view">     
     <apex:param id="aname" name="interviewDate" value="" />
 </apex:actionFunction>

/*Call the javaScript from here*/
<apex:commandLink onclick="doSave('{!$Component.interviewDate}');">               
                       <apex:commandButton value="Save"/>
                   </apex:commandLink>

/*get the parameter in controller*/
String interviewdate=Apexpages.currentPage().getParameters().get('interviewDate');

Refer this URL:  http://www.jitendrazaa.com/blog/salesforce/passing-parameter-in-actionfunction-in-visualforce/​
Thank You
Mohd Rais

All Answers

Shruti SShruti S
Please use the below code -

Visualforce page code: 
<li>
    <a href="" onclick="getProduct('{!fa.Family}'); return false;">{!fa.Family}</a>
</li>

<apex:actionFunction action="{!searchByFamily}" name="getProductFamily" >
    <apex:param name="family" value="" />
</apex:actionFunction>

<script>
    function getProduct( family ) {
        getProductFamily( family );
    }
</script>

Controller code:
public string family { get; set; }

public void searchByFamily() { 
    family = ApexPages.currentPage().getParameters().get( 'family' );
    
    String searchquery = 'select ProductCode,Name,ImageName__c,(Select UnitPrice,Pricebook2.Name From PricebookEntries where IsActive=True)  from Product2 where Family=:family'; 
    
    MyProducts = Database.query(searchquery); 
}
dai tran 6dai tran 6
family still is null
Shruti SShruti S
In this line below - 
<a href="" onclick="getProduct('{!fa.Family}'); return false;">{!fa.Family}</a>
where in you have the method getProduct, can you verify '{fa.Family}' is actually having a family in there ?
dai tran 6dai tran 6
Yes, it is exist.
Ajay K DubediAjay K Dubedi
Hi Dai,
Please understand this.
you need write the value of your list var {value="{!fa.id}"}.

<apex:actionSupport event="onclick" action="{!searchByFamily}" ReRender="conpgblk">
  <apex:param assignTo="{!family}" name="familyname" value="{!fa.id}"/>//var of your list(searchquery)ex-fa;
 </apex:actionSupport>

Please let me know if you have any query.
Please mark it as best Answer if you find it helpful.

Thank You
Ajay Dubedi
dai tran 6dai tran 6
Can not use apex:actionFunction ?
Mohd  RaisMohd Rais
Hi Dai,
Yes, You can use apex:actionFunction.
In visualforce, there is a method for passing parameters from visualforce page to controller using javascript and actionFunction. Here is the example;
/*JavaScript*/
<script type="text/javascript">
function doSave(date) {
    paraFunction(document.getElementById(date).value);
}
</script>

/*Action Function*/
<apex:actionFunction name="paraFunction" action="{!saveInterviewDate}" rerender="view">     
     <apex:param id="aname" name="interviewDate" value="" />
 </apex:actionFunction>

/*Call the javaScript from here*/
<apex:commandLink onclick="doSave('{!$Component.interviewDate}');">               
                       <apex:commandButton value="Save"/>
                   </apex:commandLink>

/*get the parameter in controller*/
String interviewdate=Apexpages.currentPage().getParameters().get('interviewDate');

Refer this URL:  http://www.jitendrazaa.com/blog/salesforce/passing-parameter-in-actionfunction-in-visualforce/​
Thank You
Mohd Rais
This was selected as the best answer
dai tran 6dai tran 6
Hi @Mohd Rais Saifi, i had try code of  @Shruti S, but it still return parameter is null.
dai tran 6dai tran 6
Thank you, i miss rerender="view"