How to redirect to a new VF page with command link and outputlink?
29,379
Solution 1
You didn't indicate how to retrieve the parameter in the desintation Visualforce page controller. 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');
}
Solution 2
You would need to use the PageReference class.
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;
instead of new PageReference('/apex/PageName');
as described here.
Author by
motti10
Updated on July 09, 2022Comments
-
motti10 almost 2 years
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}"
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>
-
motti10 over 12 yearsThanks, I do not have a button, I am clicking on a link (Asset name) in a column. </apex:outputLink> works, but it cannot call a method in controller