Friday, June 16, 2017

apex:actionFunction with apex:param example.

1. Create an apex class as below example.
/**
 * Controller class for actionFunction with passing parameter example.
 *
 **/
public with sharing class ActionFunctionExmpCtrl
{
 //Variable for input text used in VF.
 public String firstName{get;set;}
 //Variable responsible for holding param value assigned in from VF.
 public String param1{get;set;}

 //action method called from actionFunction.
 public void method1(){
  System.debug('Parameter passed is '+ param1);
 }
}

2. Create a page like below example.

<apex:page controller="ActionFunctionExmpCtrl">
<script>
/**
 * JS method call from onClick operation.
 */
function doJSMethod(fst_name) {
//Varibale to fetch the valuse passed as a parameter on onClick event.
var fstNm = document.getElementById(fst_name).value;
//actionFunction name with parameter.
callMethod1(fstNm);
}
</script>

<apex:form id="formId">
First Name: <apex:inputText id = "f_Nm" value="{!firstName}"/><br/>
<apex:inputCheckbox onclick="doJSMethod('{!$Component.f_Nm}')"/>Click on checkbox to pass First Nmae as parameter

<!-- apex:actionFunction with apex:param -->
<apex:actionFunction action="{!method1}" name="callMethod1" rerender="formId" >
       <apex:param assignTo="{!param1}" name="prmNm" value=""/>
   </apex:actionFunction>

    </apex:form>

</apex:page>

LWC to LWC Communication using Lightning Messaging Service (Part - 2)

In my previous post ( previous post link ) we have learn how to create a Lightning Messaging Service with 6 steps and today we will use the ...