2013-07-04 78 views
0
//Apex page 
<apex:page controller="MyController" tabStyle="Account" showChat="false" > 
    <apex:form > 
     <apex:pageBlock title="Congratulations {!$User.FirstName}"> 
      You belong to Account Name: <apex:inputField value="{!account.name}"/> 
      Annual Revenue: <apex:inputField value="{!account.AnnualRevenue}" required="true"/> 
      <apex:commandButton action="{!save}" value="save"/></apex:pageblock> 
    </apex:form> 
</apex:page> 

我的代碼保存數據到我的帳戶successfully.But,字段不清除保存的數據後清除的Fileds直到我因爲按刷新按鈕無法使用頂點代碼

//Apex Class 

public class MyController { 


    private Account account; public Account getAccount(){ 
    if(account == null) 
    account=new Account(); 
    return account; 
    } 
    public PageReference save(){ 
    insert account; 
    return null; 
    } 
} 

My code is saving the data to my account successfully.But,the fields are not clearing until i press refresh button. 

So, anyone can guide me to clear the page after saving my data? 
+0

它應該刷新你的頁面我不能看到問題。然而,你是否嘗試過使用apex的rerender屬性:commandButton? –

回答

1

賬戶值在視圖狀態下仍然可用。 在頁面引用方法中添加另一行,這應該有所幫助。這樣的事情:

public PageReference save(){ 
    insert account; 
    account=null; 
    return null; 
}