Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
88
rated 0 times [  94] [ 6]  / answers: 1 / hits: 20124  / 11 Years ago, fri, january 10, 2014, 12:00:00

How can I call a controller method from VisualForce page without any onclick event happening?
My VisualForce page would be like



<apex:page standardController=Account> 

<script>
/* Here i need to call a controller class with out any onclick event. It should load by itselef */

</script>

</apex:page>


and my controller class will be like



public class OrderPadController {
/* this will be the constructor */

public PageReference openPage() {
PageReference newpage = new Pagereference('/apex'+'/pagetoopen'+'?aid='+a.id);
openorderpadembed.setRedirect(false);
return openorderpadembed;
}


From my VisualForce page I need to call the method openPage().



Please help me out


More From » salesforce

 Answers
-1

You can use JavaScript Remoting for Apex Controllers in the following manner:



<apex:page standardController=Account extensions=OrderPadController>
<script src=//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js></script>
<script>
window.$j = jQuery.noConflict();
$j( document ).ready(function() {
OrderPadController.openPage(function(result, event){

console.log(result);
window.open(result,_self);

});
});

</script>
</apex:page>


public class OrderPadController {
//

@remoteAction
public PageReference openPage() {
PageReference newpage = NEW Pagereference('/apex' + '/pagetoopen' + '?aid=' + a.id);
openorderpadembed.setRedirect(false);
return openorderpadembed;
}
}

[#73260] Thursday, January 9, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jamir

Total Points: 736
Total Questions: 97
Total Answers: 101

Location: Cayman Islands
Member since Fri, Mar 4, 2022
2 Years ago
jamir questions
;