【问题标题】:How to redirect to a new VF page with command link and outputlink?如何使用命令链接和输出链接重定向到新的 VF 页面?
【发布时间】:2012-02-01 16:34:19
【问题描述】:

我有一份资产清单

Name:  column 2:  etc

A1      C1        b1
A2      c2        b2

当我点击 A1 时,我在内部调用 action="{!assetClicked}" 来执行一些逻辑,但我无法将其重定向到另一个 Visual Force 页面 如果我使用我可以链接到另一个 VF 页面,但不能执行 action="{!assetClicked}"

有没有办法将它们组合在一起或其他方式?

页面代码:

<apex:form >
  <apex:commandLink action="{! assetClicked}" value="{!wn.name}" id="theCommandLink"> 
    <apex:param value="{!wn.name}" name="id" assignTo="{!selectedAsset}" ></apex:param>
    <apex:outputLink value="/{!wn.id}" id="eventlink">{!wn.name}</apex:outputLink>
  </apex:commandLink> 
</apex:form>

【问题讨论】:

    标签: salesforce apex-code visualforce force.com


    【解决方案1】:

    您需要使用PageReference 类。

    这是文档中的一个修改示例:

    // selected asset property
    public string selectedAsset {get;set;}
    
    public PageReference assetClicked() 
    {
        // Your code here
    
        PageReference redirect = new PageReference('/apex/PageName'); 
    
        // pass the selected asset ID to the new page
        redirect.getParameters().put('id',selectedAsset); 
        redirect.setRedirect(true); 
    
        return redirect;
    }
    

    或者,您可以使用Page.PageName; 代替new PageReference('/apex/PageName');,如here 所述。

    【讨论】:

      【解决方案2】:

      您没有说明如何在目标 Visualforce 页面控制器中检索参数。我在另一个论坛上找到了这个:

      // Assuming the parameter is 'id' after redirecting to page2 you can retrieve the paramter thus
      public customcontrollerpage2() {
          String ID = ApexPages.currentPage().getParameters().get('id');
      }
      

      【讨论】:

        【解决方案3】:

        在按钮方法中,在方法末尾添加类似这样的内容:

        PageReference pr = new PageReference('/apex/YOUR_PAGE_NAME');
        
        return pr;
        

        【讨论】:

        • 谢谢,我没有按钮,我点击列中的链接(资产名称)。 有效,但不能调用控制器中的方法
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-11-26
        • 2014-10-06
        • 1970-01-01
        • 1970-01-01
        • 2019-04-20
        • 2023-03-20
        • 1970-01-01
        相关资源
        最近更新 更多