我知道這是怎麼保存記錄如何實現「取消」功能在VisualForce頁
<apex:commandButton action="{!save}" value="Save"/>
我希望有一個按鈕,不保存當前記錄(即取消)並導航到保存的記錄列表(即該對象類型的對象列表)。
事情是這樣的......
<apex:commandButton action="{!cancel}" value="Cancel"/>
我知道這是怎麼保存記錄如何實現「取消」功能在VisualForce頁
<apex:commandButton action="{!save}" value="Save"/>
我希望有一個按鈕,不保存當前記錄(即取消)並導航到保存的記錄列表(即該對象類型的對象列表)。
事情是這樣的......
<apex:commandButton action="{!cancel}" value="Cancel"/>
的對象列表視圖是你的基本URL /爲你的對象/ O的3個字母前綴,例如:
https://na1.salesforce.com/a0C/o
所以你可以創建一個操作方法,該方法返回Pagereference
並帶有相應的URL並設置爲重定向(pr.setRedirect(true)
)。
或者,你可以用你的控制器作爲擴展到標準控制器,只是call cancel on the standard controller:
// controller extension
public class TimeSheetExtension
{
ApexPages.standardController m_sc = null;
public TimeSheetExtension(ApexPages.standardController sc)
{
m_sc = sc;
}
public PageReference doCancel()
{
return m_sc.cancel();
}
}
// page
<apex:commandButton action="{!doCancel}" value="Cancel"/>
請注意,這並不一定帶你到列表視圖,它會返回到在進入VF頁面之前查看的最後一頁。
您還應該將即時標籤添加到您的取消按鈕,以便表單在執行取消操作之前不會運行任何驗證。
<apex:commandButton action="{!cancel}" immediate="true" value="Cancel"/>
同時將取消操作visualforce你應該停止以下的任何一個方法的形式validation.Use停止根據您的要求表單驗證。
方法1:
在visualforce頁 使用DOCTYPE HTML-5意味着你應該使用HTML-formnovalidate和immediate
取消按鈕。例如
<apex:commandButton action="{!cancel}" value="Cancel" immediate="true"
html-formnovalidate="formnovalidate" />
方法2:
你應該使用immediate
鍵字只需要停止表單驗證。例如
<apex:commandButton action="{!cancel}" value="Cancel" immediate="true"/>
我總是嘗試使用控制器方法,因爲理論上它們的保護不受URL格式的更改。 –
該對象記錄的所有對象ID在開始時將具有相同的3個字母,但正如Jeremy所說,最好在可能的情況下使用標準操作。你應該可以通過在構造函數中添加一個標準控制器參數並修改''標籤,使其具有'standardController =「MyObject__c」extensions =「MyCustomController」' –
這個不起作用當通過返回null來取消ajax方式時。我將無效數據保存到年份字段和字段給我錯誤。當取消它回到只讀視圖,但數據變成無效數據。但是,刷新頁面時,無效數據不存在,並顯示以前的數據 – powerfade917