Salesforce 如何使用命令链接和输出链接重定向到新的VF页面?
我有一份资产清单Salesforce 如何使用命令链接和输出链接重定向到新的VF页面?,salesforce,apex-code,visualforce,force.com,Salesforce,Apex Code,Visualforce,Force.com,我有一份资产清单 Name: column 2: etc A1 C1 b1 A2 c2 b2 当我单击A1时,我在其中调用action=“{!assetClicked}”来执行一些逻辑,但我无法将其重定向到另一个VisualForce页面 如果我使用,我可以链接到另一个VF页面,但不能执行action=“{!assetClicked}” 有没有一种方法可以将它们结合在一起,或者其他方法 页面代码: <apex:form >
Name: column 2: etc
A1 C1 b1
A2 c2 b2
当我单击A1时,我在其中调用action=“{!assetClicked}”来执行一些逻辑,但我无法将其重定向到另一个VisualForce页面
如果我使用,我可以链接到另一个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>
{!wn.name}
在按钮方法中,在方法末尾添加如下内容:
PageReference pr = new PageReference('/apex/YOUR_PAGE_NAME');
return pr;
在button方法中,在方法末尾添加如下内容:
PageReference pr = new PageReference('/apex/YOUR_PAGE_NAME');
return pr;
你需要使用这个类
以下是文档中的一个修改示例:
// 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
而不是新的页面引用('/apex/PageName')代码>如上所述 您需要使用该类
以下是文档中的一个修改示例:
// 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
而不是新的页面引用('/apex/PageName')代码>如上所述 您没有指明如何在Destination 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');
}
您没有指明如何在Destination 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');
}
谢谢,我没有按钮,我正在单击列中的链接(资产名称)。工作正常,但它无法调用ControllerHanks中的方法,我没有按钮,我正在单击列中的链接(资产名称)。工作,但它无法在控制器中调用方法