Search code examples
salesforceapex-codevisualforceforce.com

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}"

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>

Solution

  • 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');
    }