You need to sign in to do that
Don't have an account?

Override Save() method
Does anyone have a good code sample of a Save() method that refreshes the vf page on itself? OR can help me with my code below?
I have a vf form accessed via a sites page ...on save, i want to have the form insert the data and then refresh the newly created page.
I tried to do this via onclick action on the command:save ..but doesnt seem to work.
here is my current approach (not working)
<apex:commandButton action="{!save}" value="Calculate" onclick="back();"/>
<script type="text/javascript">
function back()
{
window.parent.location.href='{!$Page.FAA_Compensation_Calculator}?id={!$CurrentPage.parameters.id}&txt={!$CurrentPage.parameters.txt}';
}
</script>
Tx!
Hello ;
Change your command button as below.
<apex:commandButton action="{!save}" value="Calculate"/>
Your controller should be as below.
public abstract class MyController{
Apexpages.StandardController controller;
public MyController(Apexpages.StandardController c){
controller = c;
}
public PageReference save() {
controller.save();//invoke standard Save method
return Apexpages.currentPage();//refresh current page
}
}
All Answers
Since in the action attribute of commandbutton you are specifying "SAVE"...it works as the standard salesforce save.....
To overide use the following syntax :
<apex:commandbutton value = "Save" action = "Save_Form"/>
you will need to create a funcion Save_Form in your apex controller and then write the logic inside this function....
here is a simple code...
public class mysample
{
public string studentName
{ get;set; }
public string studentClass
{ get;set; }
public PageReference Save_Form()
{
Student__c objStudent = new Student__c();
objStudent.Name = studentName;
objStudent.Class__c = studentClass;
insert objStudent;
PageReference pr = new PageReference('/'+objStudent.Id);
pr.setRedirect(true);
return pr;
}
}
Hello ;
Change your command button as below.
<apex:commandButton action="{!save}" value="Calculate"/>
Your controller should be as below.
public abstract class MyController{
Apexpages.StandardController controller;
public MyController(Apexpages.StandardController c){
controller = c;
}
public PageReference save() {
controller.save();//invoke standard Save method
return Apexpages.currentPage();//refresh current page
}
}
How would I implement this for the Edit Page in the example blog application (see http://wiki.developerforce.com/index.php/Building_a_Blogging_Application_Using_Visualforce)?
The code provided doesn't seem to work because the oncomplete page redirect never happens.
[LINK now FIXED - I hate this BBS, has anyone at Dreamforce looked at vBulletin?]