如何使用命令链接和outputlink重定向到新的VF页面?

mot*_*i10 1 salesforce force.com visualforce apex-code

我有一份资产清单

Name:  column 2:  etc

A1      C1        b1
A2      c2        b2
Run Code Online (Sandbox Code Playgroud)

当我点击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>
Run Code Online (Sandbox Code Playgroud)

Mat*_*t K 7

您需要使用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;
}
Run Code Online (Sandbox Code Playgroud)

或者,您可以使用Page.PageName;而不是此处new PageReference('/apex/PageName');所述.

  • 请单击答案旁边的复选标记,如果它适合您,请接受它.谢谢! (2认同)