You need to sign in to do that
Don't have an account?

Unable to pass parameter using Action Function
Hi,
For some odd reason, I'm unable to pass the parameter using APEX:ACTIONFUNCTION.
Code Snippet:
VF PAGE:
<apex:page standardController="Service_Catalogue__c" extensions="serviceCatalogueCtrl">
<script>
function fnChange(a)
{
alert('Hello Param'+a);
testJs(a);
alert(a);
}
<apex:form>
<apex:actionFunction name="testJs" action="{!testJs}" rerender="" >
<apex:param value="" id="y" assignTo="{!subCategory}" />
</apex:actionFunction>
<apex:inputField value="{!Service_Catalogue__c.Category__c}"/>
<apex:inputField value="{!Service_Catalogue__c.SubCategory__c}" onchange="fnChange(this.value);" />
</apex:form>
</apex:page>
APEX CLASS:
public class serviceCatalogueCtrl {
public string subCategory{get;set;}
public serviceCatalogueCtrl(ApexPages.StandardController controller) {
}
public PageReference testJs()
{
system.debug('Hello subCategory @@'+subCategory);
return null;
}
}
Service catalogue is my custom object which has 2 picklist fields category and subcategory.
I want to pass the value that I selected in subcategory field and pass it to my controller for further processing.
But for some reason subcategory value is not getting set while trying to set in actionfunction.
It looks simple but I'm missing something.
Many thanks in advance for your help:)
Thank You!
Hi,
Try following code, I have tested its working.
Please Change Account to your custom object and input in both input field.
VF Page:
<apex:page standardController="Account" extensions="serviceCatalogueCtrl">
<script>
function fnChange(a)
{
// first make sure 'a ' is not null here
alert('Hello Param'+a);
testJs(a);
alert(a);
}
</script>
<apex:form>
<apex:actionFunction name="testJs" action="{!testJs}" rerender="" >
<apex:param name="param" value="" id="y" assignTo="{!subCategory}" />
</apex:actionFunction>
<apex:inputField value="{!Account.Name}"/>
<!--if this field is picklist then use
<apex:inputField value="{!Account.Name}" onchange="fnChange(this.value);" />
</apex:form>
</apex:page>
Apex class:
public class serviceCatalogueCtrl {
public string subCategory{get;set;}
public serviceCatalogueCtrl(ApexPages.StandardController controller) {
}
public PageReference testJs()
{
system.debug('Hello subCategory @@'+subCategory);
return null;
}
}
/**If this post helps you then please mark it as a solution and don't forget to give me kudo's by clicking star aside.***/
Thanks,
www.grazitti.com
All Answers
Hi,
Try following code, I have tested its working.
Please Change Account to your custom object and input in both input field.
VF Page:
<apex:page standardController="Account" extensions="serviceCatalogueCtrl">
<script>
function fnChange(a)
{
// first make sure 'a ' is not null here
alert('Hello Param'+a);
testJs(a);
alert(a);
}
</script>
<apex:form>
<apex:actionFunction name="testJs" action="{!testJs}" rerender="" >
<apex:param name="param" value="" id="y" assignTo="{!subCategory}" />
</apex:actionFunction>
<apex:inputField value="{!Account.Name}"/>
<!--if this field is picklist then use
<apex:inputField value="{!Account.Name}" onchange="fnChange(this.value);" />
</apex:form>
</apex:page>
Apex class:
public class serviceCatalogueCtrl {
public string subCategory{get;set;}
public serviceCatalogueCtrl(ApexPages.StandardController controller) {
}
public PageReference testJs()
{
system.debug('Hello subCategory @@'+subCategory);
return null;
}
}
/**If this post helps you then please mark it as a solution and don't forget to give me kudo's by clicking star aside.***/
Thanks,
www.grazitti.com
@Grazitti
Thanks for your reply
The alerts are working fine.only problem is it not getting printed in the controller.
Have you got that printed in the system debug?
The below system debug line is displayed as null to me.
system.debug('Hello subCategory @@'+subCategory);
Did you get the selected value of the picklist?
Hi,
In what way are you unable?
If it compiles but you get nothing, then my guess is that it's because the value is empty.
HTH / Niklas
@nickwick thanks for your reply...
I'm missing the name attribute while using the apex:param tag.So that i s causing the problem.
Although i'm not sure why we require the name attribute, it is what causing the problem.
If anyone knows the reason, please enlighten me on what is the need for name attribute.
Thank You!
Hi Sachin,
yes, I got value in debug as following. Please use same code just by replacing object name and field name that I have given .
@ Grazitti
It's working fine now.I have already accepted your answer as solution.
I missed the name attribute in the Apex:Param tag, which is causing the issue.
Anyway thanks for the help:-)
When function profileLinkClick is invoked, I can see the value of billInfoId in Firebug console, but the debug statement on controller side always print 'null' on billHistProfId.
Not sure what I did wrong. Appreciate your help here.
VF page:
<script>
function profileLinkClick(billInfoId) {
console.debug('In profileLinkClick(): poid=' + billInfoId);
launchBillProfilePage(billInfoId);
}
</script>
<apex:actionfunction name="launchBillProfilePage" action="{!BillProfPage}">
<apex:param name="billHistProfId" assignTo="{!billHistProfId}" value="" />
</apex:actionFunction>
Controller:
public String billHistProfId {get; set;}
......
public PageReference BillProfPage(){ // Creating page reference for billing history profile page PageReference billProfPage = Page.BillingHistoryProfileList; // adding URL paarameter (billing info POID) that is coming from billing history page. It is later // used to identify billing profile uniquely. system.debug('billHistProfId' + billHistProfId);
.......