2

I found this block of code in the Salesforce docs:

<apex:page>
   <h1>Linked</h1>
      <apex:outputLink value="{!$Page.otherPage}">
           This is a link to another page.
      </apex:outputLink>
</apex:page>

I'm unfamiliar with the !Page global variable.

Could someone tell me how exactly I could assign otherPage a value?

The URL I want to pass into otherPage can change and is accessed through my Controller, so I can't just attach the name of my page to it.

I need to assign a variable and update it when the page loads.

2 Answers 2

2

As bananka mentioned, you should read up on the documentation for that particular global variable. You can't assign to it.

If you want to dynamically link to a PageReference from a controller or extension:

public with sharing class MyController
{
    // set the value internally wherever you need
    public PageReference myLink { get; private set; }
}

Then your page would look like:

<apex:page controller="MyController">
    <apex:outputLink value="{!myLink}" rendered="{!NOT(ISNULL(myLink))}">
        This is a link to another page.
    </apex:outputLink>
</apex:page>
1

'otherPage' is the API name of another Visualforce page in your salesforce environment. You need to put the name of the page you want to redirect to instead of 'otherPage'.

$Page is a global variable and you can find more info about it in the documentation.

3
  • The URL I want to pass into otherPage can change, so I can't just attach the name of my page to it. I need to assign a variable and update it when the page loads.
    – Daft
    Commented Apr 21, 2015 at 14:08
  • Than bind to a controller property of the PageReference Type. Commented Apr 21, 2015 at 14:13
  • @SamuelDeRycke could you possibly expand that into an answer? It sounds like it's just what I need.
    – Daft
    Commented Apr 21, 2015 at 14:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .