You need to sign in to do that
Don't have an account?
Call multiple apex controller methods after click Javascript Function using Command Link
Hi All,
I would like to call apex controller method when we move one page to another page. I have to also check data modification on Visualforce page then display Confirm Dailog box. If User Click 'Yes' then modified data get saved in table, if user click 'Cancel' of dailog box then it will move for next page without any data save.
Code Sample::
var flag='false';
function goPage(pages){
if(flag=='true'){
if(confirm('Before move to the next page. Do you want to save modified Status? ')== true){
saveMePermanent(); // Simaple Javascript Funciton
nextAfterSave(); // This is apex controller method
}
}
document.getElementById("pNumber").value = pages;
nextBeforeSave(); // this is apex controller method
}
Visual force Page
<apex:actionFunction name="nextAfterSave" action="{!submitStatus}" />
<apex:actionFunction name="nextBeforeSave" action="{!next}" />
<table >
<tr>
<td>
<apex:panelGrid columns="50">
<apex:repeat value="{!activePages}" var="pages">
<apex:commandLink onclick="goPage({!pages});" >{!pages}</apex:commandLink>
</apex:repeat>
<input type="hidden" name="pageNumber" value="" id="pNumber"/>
</apex:panelGrid>
</td>
</tr>
</table>
I dont know why its not working. I have seen some sample code also that have written as i have given in sample.
Is i am missing something in this code?
Please help me.
Thanks in Advance
R.K
Bob's definitely correct here. You need to prevent bubbling up to the internal library's default postback link handler, which is a form submission that refreshes the entire page (or named elements if using reRender as well). So, changing the attribute to: "goPage({!pages}); return false;" should be sufficient.
All Answers
I think you need to add a return false; statement to the end of your goPage function. If you don't the actionfunction will fire and then the commandlink will continue to postback the page, putting you into an interesting race condition. By returning false, you tell the browser not to complete the default action associated with the link.
Bob's definitely correct here. You need to prevent bubbling up to the internal library's default postback link handler, which is a form submission that refreshes the entire page (or named elements if using reRender as well). So, changing the attribute to: "goPage({!pages}); return false;" should be sufficient.
Hi,
i am also having same requirement. but i am not getting the proper order of the code. So please send me the complete code. Means VF page and its controller also. still u are getting any errors, i can rectify them.