You need to sign in to do that
Don't have an account?
Urgent: PageReference is not working
Hi All,
I have a custom button on VF page (say open), when clicking on the button the page should open in a new window; it is working when Development mode is on (checked) , when switched off the development mode the page is opening inline on VF page only. Any help is highly appreiciated.
<apex:pageblockButtons location="top">
<apex:commandButton action="{!tOpen}" value="Open"/>
</apex:pageblockButtons>
public PageReference tOpen(){
PageReference pref= new PageReference('/'+ tid +'?retURL=%2F'+cid);
pref.setRedirect(true);
return pref;
}
Thanks a ton inadvance!
I wouldn't expect this to open in a new window regardless of developer mode - you have just coded a button to submit the form and the action method returns a client side redirect. There's nothing in there to open a new window.
You can't mark the page reference to open a new window, as that isn't part of the HTTP protocol. If you just want to open a new window to another URL, you'd do better to have an apex:commandlink, which allows you to specify a target, or an onclick handler to open the window via javascript.
All Answers
I wouldn't expect this to open in a new window regardless of developer mode - you have just coded a button to submit the form and the action method returns a client side redirect. There's nothing in there to open a new window.
You can't mark the page reference to open a new window, as that isn't part of the HTTP protocol. If you just want to open a new window to another URL, you'd do better to have an apex:commandlink, which allows you to specify a target, or an onclick handler to open the window via javascript.
Thanks for th reply bob_buzzard.
Can you please give sample code for onclick hanlder to open the window.
Thanks a ton in advance.
Do you need to hit the action method first, or is it just to open a URL from one of the controller properties?
I want to open a URL when clicked on Command button.
Thanks
That doesn't help I'm afraid. Do you need to hit the action method first, or does the page know enough to create the URL.
when clicked on the button, the page should redirect to the url specified in the action method.
Actually I am overriding Activity History section here , when cliked on open, repective Activity History should open in a new page.
Thank you.
You can open a URL from a command link as follows:
Note the "return false" at the end of the onclick handler - this stops the page being submitted back as well as the popup window being opened.
Thanks for the reply bob, how to use query paramters in the URL, say ('/'+ tid +'?retURL=%2F'+cid) instead of 'google.co.in' in the give sample code.
Thank you.
Assuming you have controller properties for tid and cid, you should be able to drop them into the URL:
another way to do this is to have a getter in your controller that builds the URL and allows the page to use that directly.
The parent location is essentially replaced with the new location, keeping the previous page in history so that the user can still access the previous page using the back button.