You need to sign in to do that
Don't have an account?
Apex actionfunction does not retain value
Hi,
Below is my VF page and Controller class code. I have a look-up field on my VF page. I type in city name and click on Add. I have java script function (I think it is AJAX) which shows this value on Apex InputTextArea. Everything works except that the selected value appears on the InputTextArea control and disappears. I am suspecting something to do with page refresh but not sure.
I have highlighted the important blocks of code.
Any help is much appreciated. Thanks in advance.
VF Page-
<apex:page standardController="Leg__c" extensions="TripLegsGroupBookController" recordSetVar="Leg__c" tabStyle="Leg__c">
<apex:pageblock title="Group book legs">
<apex:form id="mForm" >
<script type="text/javascript">
function doSave(sname) {
CityName(document.getElementById(sname).value);
}
</script>
<apex:actionFunction name="CityName" action="{!ReadCityNames}" rerender="SelctCity">
<apex:param name="CityNames" value="" assignTo="{!stcityName}" />
</apex:actionFunction>
<apex:pageblockSection columns="2">
<apex:pageblockSectionItem >
<apex:outputLabel value="City travelling:"/>
<apex:outputPanel >
<apex:inputField id="TravelCity" value="{!GroupLeg.To_City__c}" />
<apex:commandLink value="Add" onclick="doSave('{!$Component.TravelCity}')"/>
</apex:outputPanel>
</apex:pageblockSectionItem>
<apex:pageblockSectionItem >
<apex:outputLabel value="Selected city/ies:"/>
<apex:outputPanel id="SelctCity">
<apex:inputtextarea id="SelCity" value="{!stcityName}"/>
</apex:outputPanel>
</apex:pageblockSectionItem>
</apex:pageBlockSection>
</apex:form>
</apex:pageblock>
</apex:page>
Controller class
Public class TripLegsGroupBookController{
Private final Leg__c myTripLeg;
Public String stCityName{get; set;}
public String TCity{get; set;}
Public TripLegsGroupBookController(ApexPages.StandardSetController LegStdController){
this.myTripLeg=(Leg__c) LegStdController.getRecord();
}
//************************************
Public Leg__c getGroupLeg(){
Return myTripLeg;
}
//************************************
Public PageReference ReadCityNames(){
stcityName=TCity + ', ' + Apexpages.currentpage().getParameters().get('CityNames');
TCity=stcityName;
return null;
}
//************************************
Public String getTCity(){
return stcityName;
}
//************************************
Public String getstcityName(){
return stcityName;
}
}
commandlink works server-side.So you execute an ajax request after this commanlink post the all form to the server.
Please try to rerender particular part of page like as:
<apex:commandLink reRender="panel" onclick="...."/>
<apex:outputpanel id="panel">
</apex:outputpanel>
Thanks for your suggestion.
I have made further changes but this has resulted in new problem. While the value is retained in the InputTextArea it is only null.
Earlier I could see name of the selected city like null, London or null, Paris. Now I see null, null.
Do I have to make changes to my controller class??
Thanks.