3

I am trying to override a custom object new and edit actions with a simple visualforce page. The desire is to not need a custom controller and just use the standard controller methods.

<apex:page standardController="Site__c" >
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}" />
        ...
    </apex:form >
</apex:page>

Which works fine, but when I try to move the save action to apex:actionFunction, and use the oncomplete to redirect.

<apex:page standardController="Site__c" >
    <script>
        function redirectBack(){...;}
    </script>
    <apex:form >
        <apex:actionFunction name="saveActionFunc" action="{!save}" oncomplete="redirectBack()" rerender="theBlock" />
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" onClick="saveActionFunc();"/>
        ...
    </apex:form >
</apex:page>

the redirectBack() is working, but it doesn't save the form.

Can you use apex:actionFunction to call standardController methods?

Note: I realized that apex:commandButton has oncomplete too, so I am not looking so much for a better way, but to better understand the limitations of actionFunction.

The documentation on each reads very similar, except one is called by AJAX request and the other by a DOM event. Also the the commandButton adds:

Note that command buttons associated with the save, edit, or delete actions in a 
standard controller are rendered only if the user has the appropriate permissions. 
Likewise, command buttons associated with the edit and delete actions are rendered 
only if a record is associated with the page.

but I don't believe that means that only commandButtons can call standard controller methods, but what do I know.

Can anyone say for sure?

1
  • I have action and oncomplete- action will update the object.but when i run, action is not calling only oncomplete works
    – unidha
    Mar 31, 2015 at 3:52

0

You must log in to answer this question.