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

ActionFuntion Implementation
Hi
I'm trying to imlement actionFunction in my vf page, but I'm unable to do. I'm unable to display the value of my prod variable.
Here is my code.
//VF Code
<apex:page controller="ExtPosition">
<apex:form >
<apex:actionFunction action="{!productSearch}" name="productSearch" rerender="Outpano"> </apex:actionFunction>
<apex:outputPanel id="Outpano"> <br/>
Here is another Text : {!prod}<apex:OutputText value="{!prod}" />
</apex:outputPanel>
</apex:form>
</apex:page>
//Function
public class ExtPosition{
public List<String> title {get;set;}
public String OutputString {get;set;}
public String EnterData {get;set;}
public String prod{get;set;}
List<Position__c> pos = new List<Position__c>([select Name,Position_title__c from Position__c]);
public ExtPosition()
{
title = new List<String>();
{
For (Position__c p : pos)
{
title.add(p.Position_title__c);
}
}
}
public void EnterData()
{
OutputString=EnterData;
}
//List<String>
public void productSearch()
{
prod='Arun';
}
}
I'm trying to imlement actionFunction in my vf page, but I'm unable to do. I'm unable to display the value of my prod variable.
Here is my code.
//VF Code
<apex:page controller="ExtPosition">
<apex:form >
<apex:actionFunction action="{!productSearch}" name="productSearch" rerender="Outpano"> </apex:actionFunction>
<apex:outputPanel id="Outpano"> <br/>
Here is another Text : {!prod}<apex:OutputText value="{!prod}" />
</apex:outputPanel>
</apex:form>
</apex:page>
//Function
public class ExtPosition{
public List<String> title {get;set;}
public String OutputString {get;set;}
public String EnterData {get;set;}
public String prod{get;set;}
List<Position__c> pos = new List<Position__c>([select Name,Position_title__c from Position__c]);
public ExtPosition()
{
title = new List<String>();
{
For (Position__c p : pos)
{
title.add(p.Position_title__c);
}
}
}
public void EnterData()
{
OutputString=EnterData;
}
//List<String>
public void productSearch()
{
prod='Arun';
}
}
<apex:actionFunction action="{!productSearch}" name="productSearch" reRender="OutAnother"/>
please remove reRender="OutAnother
Please mark it as solution(Best Answer) if this solves your problem.
Thanks
sandhya
All Answers
Please refer below links which explains how to use action function
http://sfdcsrini.blogspot.com/2014/07/visualforce-action-function-example.html
http://www.salesforcetutorial.com/actionfunction-tag/
Please mark it as solution(Best Answer) if this solves your problem.
Thanks
sandhya
I have implemented logic implemented in above links, but couldn't get required result. Here is my code.
<apex:page controller="ExtPosition">
<script>
function product(){productSearch();}
</script>
<apex:form >
Please Input Data : <apex:inputText value="{!EnterData}"/>
<apex:commandButton value="Submit" action="{!EnterData}" rerender="Outp"/>
<apex:outputPanel id="Outp"> <br/>
Your Output is : <apex:OutputText value="{!OutputString}" /> <br/>
</apex:outputPanel>
<apex:actionFunction action="{!productSearch}" name="productSearch" reRender="OutAnother"/>
<br/>
<apex:pageBlock title="Lead Form - Enter lead details" id="OutAnother">
<apex:inputText value="{!name}"> </apex:inputText>
<apex:commandButton value="Save" onclick="product();"/> <br/><br/>
<apex:outputText value="{!firstname}"> {!firstname}</apex:outputText>
</apex:pageBlock>
</apex:form>
</apex:page>
//Controller
public class ExtPosition{
public List<String> title {get;set;}
public String OutputString {get;set;}
public String EnterData {get;set;}
public String name{get;set;}
public String firstname{get;set;}
List<Position__c> pos = new List<Position__c>([select Name,Position_title__c from Position__c]);
public ExtPosition()
{
title = new List<String>();
{
For (Position__c p : pos)
{
title.add(p.Position_title__c);
}
}
}
public void EnterData()
{
OutputString=EnterData;
}
public void productSearch()
{
firstname='Arun';
}
}
Arun
I have recieved the desired output now. However I have one query.
When I'm putting alert() method in javascript then only its working, when I'm removing alert() then its not working. Any idea why it is so?
productSearch();
alert("Search Product again");
Arun.
<apex:actionFunction action="{!productSearch}" name="productSearch" reRender="OutAnother"/>
please remove reRender="OutAnother
Please mark it as solution(Best Answer) if this solves your problem.
Thanks
sandhya