[英]How to redirect to a new VF page with command link and outputlink?
I have a list of Assets 我有资产清单
Name: column 2: etc
A1 C1 b1
A2 c2 b2
When I click on A1, I call action="{! assetClicked}" within to do some logic, but I cannot redirect it to another Visual Force Page If I use I can link to another VF page, but cannot do action="{! assetClicked}" 当我单击A1时,我在其中调用action =“ {!assetClicked}”来执行一些逻辑,但是我无法将其重定向到另一个Visual Force页面。如果使用,我可以链接到另一个VF页面,但是不能执行action =“ { !assetClicked}”
Is there a way to combine them together or some other way around? 有没有办法将它们结合在一起或其他方式?
Page Code: 页面代码:
<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>
You would need to use the PageReference class. 您将需要使用PageReference类。
Here's a modified example from the documentation: 这是文档中的修改示例:
// 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;
}
Alternatively, you could use Page.PageName;
或者,您可以使用
Page.PageName;
instead of new PageReference('/apex/PageName');
而不是
new PageReference('/apex/PageName');
as described here . 作为描述在这里 。
You didn't indicate how to retrieve the parameter in the desintation Visualforce page controller. 您没有指出如何在目标Visualforce页面控制器中检索参数。 I found this in a different forum:
我在另一个论坛中找到了这个:
// Assuming the parameter is 'id' after redirecting to page2 you can retrieve the paramter thus
public customcontrollerpage2() {
String ID = ApexPages.currentPage().getParameters().get('id');
}
In button method add something like this at the end of the method: 在button方法中,在方法末尾添加以下内容:
PageReference pr = new PageReference('/apex/YOUR_PAGE_NAME');
return pr;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.