如何实现“取消"VisualForce 页面中的功能 [英] How to implement "Cancel" functionality in a VisualForce Page

查看:30
本文介绍了如何实现“取消"VisualForce 页面中的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是如何保存记录

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).

这样的东西...

<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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆