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
mt0859mt0859 

Another (different!) error when trying to set the URL for an iframe

Hi all,

 

I have a visual force page (with its own custom ontroller) in a managed package which tries to display an iFrame where the URL is set in the page controller

 

i.e.

<apex:iframe src="{!PropURLToDisplay}" scrolling="true" rendered="true"/>

 

 

 However, when I set the variable on the page to be, "URLFOR($Action.Account.New)" using:

 

public string getPropURLToDisplay() { string URL = 'URLFOR($Action.Account.New)'; return URL;}

 

 

 I always get the VF page erroring with the message:

 

Page MyPackageName__URLFOR($Action.Account.New) does not exist

 

Is this a bug? Are there any ways to get around this?

 

TIA,

 

Marco 

Richie DRichie D

Hi mt0859,

 

The problem is that you are returning a serverside function (URLFOR) in a string to go directly to the output. By the time the {!PropURLToDisplay} has been calculated and returned it is then not possible for the system to then recall any text and rerun the parser and replace what look like server tags with the correct output.

 

What you may need to do is return a proper pageReference object from PropURLToDisplay or at least a well formed string.

 

Try having a look at the sobject Describe object and the getKeyPrefix method.

 

You may even have to turn the object into the standard HTML  iframe tag...

 

Good luck.

R.

 

jwetzlerjwetzler

Richie I'm not sure I quite understand your answer...

 

mt0859, URLFOR and $Action is Visualforce syntax, not Apex Code syntax.  You can use those in an expression on your page (so between the {!} characters) but you can't use them in Apex Code.

 

It looks to me like you don't need a method in your controller at all for this, all you need is the $Action expression.

Richie DRichie D

I suppose I'm saying that the VisualForce tag is returned via the apex code. Therefore it is just returned as a string and not a visualforce tag for the visualforce parser to then go off and process. (This is how it would hapen in .net and I'm therefore guessing thats how apex/VF work together.)

 

I tried the example of just having iframe src="{!$Action.Account.new}" and it seemed to just set the url as {!Action.Account.new} i.e. it didn't substitute the proper url into the prameter.

 

I think the function needs to return /[prefix]/e as the url to function correctly.

 

R. 

 

 

jwetzlerjwetzler

The accepted way is to use $Action instead of hacking the url (/e is the edit page anyway edit: sorry I see that's what he wants!).

 

You need the URLFOR in there too to get the actualy url.

Message Edited by jwetzler on 07-07-2009 07:52 AM
mt0859mt0859

basically, what i'm trying to do is dynamically vary the parameters in the URLFOR function so that a different page will display (my example code was much simplified for clarity in the post). These have to come from a text field on a record

 

e.g. if the field contains the string "account.new", want to take that value, add the URLFOR and other gubbins ($Action etc) required around it, then stick it in as the "src" of the iFrame so that the create new account page was displayed

 

<apex:iframe src="{!PropURLToDisplay}" scrolling="true" rendered="true"/>

 

The idea is that if the field contained say "contact.new" instead of "account.new", something different would happen.

 

I see now that this doesn't work (it's been along day), does anyone have any ideas on how i could do it? 

 

aim is: identifier from record field results in page being displayed to create certain object

 

Cheers,

 

Marco