0

当我在 commandButton 中使用标准保存操作时,它每次都会转到默认页面。

但是当我单击保存按钮时,我想切换到自定义页面..如何?

我尝试了很多这样的事情......

public Pagereference goHome(){

Pagereference to = Apexpages.currentPage();
     to.setRedirect(true);
return to;
}

或者

public Pagereference goHome(){

Pagereference to = new Pagereference('/apex/mypage?user=guest');    return to;
}


<apex:commandButton value="Save"  action="{!goHome}" />
4

2 回答 2

0

标准save()方法可以使用ApexPages.StandardController. 这是一个如何实现它的简单示例:

顶点页面:

<apex:page standardController="Account" extensions="AccountExtension">
    <apex:form >

        <apex:pageMessages />

        <apex:pageBlock title="Account">
            <apex:pageBlockSection title="Account Details">
                <apex:inputField value="{!account.Name}" />
            </apex:pageBlockSection>

            <apex:pageBlockButtons >
                <apex:commandButton action="{!Save}" value="save" />
                <apex:commandButton action="{!Cancel}" value="cancel" />
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>

</apex:page>

扩展类:

public class AccountExtension {

    ApexPages.StandardController stdController;

    public AccountExtension(ApexPages.StandardController controller) {
        stdController = controller;
    }

    public PageReference save() {
        stdController.save(); // calling standard save() method
        return null; // return 'null' to stay on same page
    }
}
于 2012-12-07T05:24:27.757 回答
0

应该很简单!检查此示例如何为您工作(您需要通过添加?id=006...URL 将页面关联到有效的机会)。

public class redirectTestCtrl{
    public Opportunity o {get;set;}

    public redirectTestCtrl(ApexPages.StandardController ctrl){
        o = (Opportunity)ctrl.getRecord();
    }

    public PageReference save(){
        upsert o;
        //return new PageReference('/home/home.jsp'); // go to home page
        return new PageReference('/' + o.AccountId);  // or to the related Account's page
    }
}

<apex:page standardController="Opportunity" extensions="redirectTestCtrl">
    <apex:outputField value="{!o.AccountId}" />
    <apex:form>
        <apex:inputField value="{!o.Name}" />
        <apex:commandButton value="Save" action="{!save}" />
    </apex:form>
    <span style="visibility:hidden">{!Opportunity.Name} {!Opportunity.AccountId}</span>
</apex:page>
于 2012-11-15T10:29:09.453 回答