function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SteveBowerSteveBower 

<apex:include pageName="{!somePageReference}"/> doesn't work. Bug?

Hi, from the VF doc on the <apex:include> tag I get:

 

pageNameThe Visualforce page whose content should be inserted into the current page. For this value, specify the name of the Visualforce page or use merge-field syntax to reference a page or PageReference.ApexPages.PageReferenceYes

 

So, I'm trying to use a Merge field to reference a pageReference.  I am brought to a blank screen with this message:

 

You cannot use a URL for this attribute. <apex:include pageName>. Please set the attribute to a Visualforce page name.

 

Here is my test code: 

 

VisualForce page:  Try_IncludeWithPageReference.page

 

 <apex:page Controller="Try_IncludeWithPageReference">

        <apex:include pageName="{!editPageRef}"/>
 </apex:page>

 

 

 Apex Controller: Try_IncludeWithPageReference.cls

 

 public with sharing class Try_IncludeWithPageReference {
    public pageReference editPageRef {get; set;}
    public Try_IncludeWithPageReference() {
        editPageRef = new pageReference('/001');
    }
}

 

 

Am I just not understanding the documentation, is this a bug, or something else? 

 

I'd appreciate any input.  Thanks, Steve.

 

Best Answer chosen by Admin (Salesforce Developers) 
SteveBowerSteveBower
Yep, just another case where VisualForce's lack of dynamic binding rears it's head.   Best, Steve.

All Answers

ApexGuyApexGuy

The problem with <apex:include pageName="{!editPageRef}"/> is in your property editPageRef. Your property is of type PageReference. It returns a PageReference. It should be of type String, since the include tag is looking for a String.

 

As far as what you are trying to do, return a standard page, I think that the error message is correct. The include tag can include only visual force pages, in other words custom but not standard pages.

SteveBowerSteveBower

Hey Apexguy, thanks for your comments, I should have tried a String.

 

So, just to continue, if you're interested...  I tried the String as you suggested:

 

public with sharing class Try_IncludeWithPageReference {
    public String editPageRef {get; set;}
    public Try_IncludeWithPageReference() {
        editPageRef = 'Try_ASimpleVFPage';
    }

}

 

Where Try_ASimpleVFPage is a trivial VF page that has a trivial controller.

 

This works fine as the String is substituted into the pageName parameter.  However, stubborn man that I am, I also tried to use a Controller, this time with a specified Page.

 

 public with sharing class Try_IncludeWithPageReference {

    public pageReference editPageRef {get; set;}
    public Try_IncludeWithPageReference() {
        editPageRef = Page.Try_ASimpleVFPage;
    }

}

 

This works as well.  Ok, perhaps the substitution is being done by implicitly calling the getURL of the pageReference.  I'm not sure?

 

So, just for **bleep**s and giggles, I tried to pass a parameter:

 

 

 public with sharing class Try_IncludeWithPageReference {

    public pageReference editPageRef {get; set;}
    public Try_IncludeWithPageReference() {
        editPageRef = Page.Try_ASimpleVFPage;
        String nut = 'Peanut';
        editPageRef.getParameters().put('nut',nut);
    }
}

 

and I get:

 

An internal server error has occurred An error has occurred while processing your request. The salesforce.com support team has been notified of the problem. If you believe you have additional information that may be of help in reproducing or correcting the error, please contact Salesforce Support. Please indicate the URL of the page you were requesting, any error id shown on this page as well as any other related information. We apologize for the inconvenience.

Thank you again for your patience and assistance. And thanks for using salesforce.com!

Error ID: 687109336-248 (-1810497108) 

 

 

I'm sure I can workaround this and come up with some alternate solution, I just wanted to see if I could get my original idea to work.  :-)

 

Thanks, Steve.

 

p.s. my use of '/001' in the original posting isn't what I'm trying to accomplish, it was just a quick test.

SteveBowerSteveBower

I wish I could go back and revise my postings when I see an error... :-)

 

This works fine as the String is substituted into the pageName parameter.  However, stubborn man that I am, I also tried to use a Controller, this time with a specified Page.

was  .... to use a pageReference, this time.....

Steve.

 

Also, just for fun,  I didn't write **bleep**s   I wrote **bleep**s

ApexGuyApexGuy
I tried the things that you said. As you said, a pagereference does work, if the page contains nothing else. I tried passing a parameter like you did, and it passes ok to the page, but does not work with the include tag. I suspect the reason is that the include tag includes a static page, and a parameter would only be included in a page that is not static.
SteveBowerSteveBower
Yep, just another case where VisualForce's lack of dynamic binding rears it's head.   Best, Steve.
This was selected as the best answer