如何实施“取消"操作? VisualForce页面中的功能 [英] How to implement "Cancel" functionality in a VisualForce Page
问题描述
我知道这是保存记录的方法
I know that this is how to save a record
<apex:commandButton action="{!save}" value="Save"/>
我希望按钮不保存当前记录(即取消),并导航到已保存记录的列表(即该对象类型的对象列表).
I want a button to NOT save the current record (ie. Cancel) and navigate to the list of saved record (ie. list of objects for that object type).
类似这样的事情...
Something like this...
<apex:commandButton action="{!cancel}" value="Cancel"/>
推荐答案
对象的列表视图是您的基本URL/对象的3个字母前缀/o,例如:
The list view for an object is your base URL / the 3 letter prefix for your object / o, for example:
https://na1.salesforce.com/a0C/o
因此,您只需创建一个操作方法即可,返回一个带有相应URL的Pagereference
并将其设置为重定向(pr.setRedirect(true)
).
So you could just create an action method that returns a Pagereference
with the appropriate URL and set to redirect (pr.setRedirect(true)
).
或者,您可以将控制器用作标准控制器的扩展,而在标准控制器上取消通话:
Alternatively, you could use your controller as an extension to a standard controller, and just 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页面之前正在查看的最后一页.
Note that this doesn't necessarily take you to the list view, it'll return you to the last page you were viewing before going to the VF page.
这篇关于如何实施“取消"操作? VisualForce页面中的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!