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
Arun Yadav 13Arun Yadav 13 

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';
 }   
    
}
Best Answer chosen by Arun Yadav 13
sandhya reddy 10sandhya reddy 10
Hi 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

sandhya reddy 10sandhya reddy 10
Hi Arun,

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
Arun Yadav 13Arun Yadav 13
Hi 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
Arun Yadav 13Arun Yadav 13
Hi Sandhya,

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.
sandhya reddy 10sandhya reddy 10
Hi 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
This was selected as the best answer