You need to sign in to do that
Don't have an account?
Sachin Gahlot
reRender attribute is not working with Controller function of type Page Reference in CommandButton
When I click on cancel button, what should happen is firstly it hsould update the list with vf page and then it should load the new page through pagr Reference. What's wrong here?
Code -
Controller -
public PageReference getBack(){
system.debug('timeZoneWrapperBackupList :'+timeZoneWrapperBackupList);
if(!timeZoneWrapperBackupList.isEmpty() && timeZoneWrapperBackupList.size()>0){
timeZoneWrapperList = timeZoneWrapperBackupList.clone(); // sachin - INC6670357
}
system.debug('timeZoneWrapperList :'+timeZoneWrapperList);
String dateIdParam = ApexPages.currentPage().getParameters().get('schDateId');
String timeIdParam = ApexPages.currentPage().getParameters().get('schTimeId');
PageReference nextPage;
if(dateIdParam !=null){
nextPage = new PageReference('/' + dateIdParam);
} else if (timeIdParam !=null){
nextPage = new PageReference('/' + timeIdParam);
} else if (programSch.Id !=null){
nextPage = new PageReference('/' + programSch.Id);
} else {
Schema.DescribeSObjectResult result = Program_Schedule__c.SObjectType.getDescribe();
nextPage = new PageReference('/'+ result.getKeyPrefix()+'/o');
}
return nextPage;
}
vf page -
<apex:commandbutton value="Cancel" onclick="return confirm('Are you sure you want to cancel?');" action="{!getBack}" rerender = "timezoneId"/>
Code -
Controller -
public PageReference getBack(){
system.debug('timeZoneWrapperBackupList :'+timeZoneWrapperBackupList);
if(!timeZoneWrapperBackupList.isEmpty() && timeZoneWrapperBackupList.size()>0){
timeZoneWrapperList = timeZoneWrapperBackupList.clone(); // sachin - INC6670357
}
system.debug('timeZoneWrapperList :'+timeZoneWrapperList);
String dateIdParam = ApexPages.currentPage().getParameters().get('schDateId');
String timeIdParam = ApexPages.currentPage().getParameters().get('schTimeId');
PageReference nextPage;
if(dateIdParam !=null){
nextPage = new PageReference('/' + dateIdParam);
} else if (timeIdParam !=null){
nextPage = new PageReference('/' + timeIdParam);
} else if (programSch.Id !=null){
nextPage = new PageReference('/' + programSch.Id);
} else {
Schema.DescribeSObjectResult result = Program_Schedule__c.SObjectType.getDescribe();
nextPage = new PageReference('/'+ result.getKeyPrefix()+'/o');
}
return nextPage;
}
vf page -
<apex:commandbutton value="Cancel" onclick="return confirm('Are you sure you want to cancel?');" action="{!getBack}" rerender = "timezoneId"/>
I trust you are doing very well.
You need to change onclick event:
Please refer to the below link with a similar discussion which might help you further with the above issue.
https://salesforce.stackexchange.com/questions/2046/how-to-add-a-confirm-dialog-to-a-command-button
https://salesforce.stackexchange.com/questions/80965/command-button-and-re-render-not-working
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks and Regards,
Khan Anas
Appretiate your help! But this is not the issue here.
What I am trying to do is update the timeZoneWrapperList List with timeZoneWrapperBackupList List in the vf page. But that is not happening. The Apex code is getting executed but databse is not getting updated.
if(!timeZoneWrapperBackupList.isEmpty() && timeZoneWrapperBackupList.size()>0){
timeZoneWrapperList = timeZoneWrapperBackupList.clone(); // sachin - INC6670357
}
In some code whenever the timeZoneWrapperList and this gets displayed in vf page, the database also gets updated, but here when I update the timeZoneWrapperList with rerendering, it's not getting updated in the database.
Not sure if the rerendering is not working or there is some other way to update the list with the database.
Hope you understand the problem.