You need to sign in to do that
Don't have an account?
CustomDataIntegrations
Hyperlink to User Saved Document
I am trying to create a hyperlink to a document saved to a User Folder. The Document is an .html file that has been saved there. The file contains some html like....
<html> <body onLoad="javascript: document.forms[0].submit();"> <form action="http://www.mysite/mypage.aspx" method="POST"> ..... input tags with values....
If I can create this same functonality in another way, I would be open to that as well. Basically I need to serve up this html that would submit the page right away.
Is there a reason why you need to do this via a saved document? I.e. could you do it via an apex:page action attribute?
If I could do it via an apex:page action attribute, that would be great. Can you give me an example of how I would go about that?
Thanks,
Can you give me a little more detail about what you are trying to achieve? In your original post you are submitting the form back to an external page - is that the requirement or are you simply trying to submit some information back to Salesforce?
I am trying to submit some information back to an external page. I would like to put a link on a page and have it serve up some .html that submits to an external page. So, if that link directs to a different apex:page that handles loading the html and then automatically submits to an external page, that would be great. The .html would consist of a few input components that have values assigned to them based on the user that is currently logged in.
Cool. In that case a page action wouldn't work unless you were happy with an HTTP GET request as opposed to a POST. An onload handler should. You should just be able to embed the form into the Visualforce page and click it onload as you would for vanilla HTML:
Something like the following:
In this case your hyperlink (presumably from a record detail page or similar) can simply open the VF page and all should happen as you expect.
So this was working fine for me for some time, but now I am not sure why this doesn't work. Now instead of submitting the html, it just opens up another instance of MainPage in a new window. What am I doing wrong?
MainPage using controller "MainPageController"
Here is the action (located in MainPageController) for the commandLink that is executed:
Below is the page, CreateNewPAF, that I am calling. It shares the same controller as the calling page.
I'm a bit lost here - where does the commandlink fit into this?
I editted my previous post to hopefully help you see what is going on.
As you are using the setRedirect=true, I'd expect a new instance of the controller to be created for the target page, as that mandates a client side redirect. Can you explain the expected behaviour to me?
I am using setRedirect=true. I need to pull the current user (not the same as the salesforce user) from the controller into html before submitting the page onload. So when I click a link, this link points to a different page and loads it in a new window. This new page is using javascript to submit the page onload.
Should I be using setRedirect = false? But wouldn't I lose any values in the controller with a new instance of the controller being created?
Hmm. That sounds about right. So what happens when you click the button? Does it open the expected page but the onload doesn't fire, or is it something else?
It actually opens up a new instance (or new page) of the MainPage that I was just on.
The only thing that seems odd to me is the combination of an action method and a target attribute. Target attributes are usually interpreted by the browser without hitting the controller, so it may be something related to that.
That said, as you are simply opening a new page, you don't need to hit an action method, you should simply be able to use:
and that will save you a round trip to the server.
This does work in opening up the new page, but it doesn't appear to be pulling in my values from the shared mainpagecontroller.
It won't - this is a new window and thus has a new instance of the controller.
Hmm, this was working properly at one point. ...Ok, so how do I get 2 properties from the first page controller to the second page controller. I will create a second controller specific to the CreatePAFPage.
I must admit I'm struggling to understand how this could have worked, given that each window maintains its own data via a separate viewstate/transaction etc. Controllers can be retained across pages but that's where the same browser window is re-used.
You can pass parameters on the URL to the child window - would that do the trick?
Although maybe I'm misunderstanding - you can use the same controller class to back both pages, but the actual controller instances will be specific to each browser window (essentially each rendered page).
So if I take away the target=blank, so that it just opens the new page in the same window... I now just get a new instance of the MainPage (calling page) in that window. This is if I go with the commandlink route and make the trip back to the server and do the redirect from the server. If I use your method with the outputlink, then it does open up that CreatePAFPage and redirect to the new page, but just does not pass my MainPageController page variables.
I'm not sure what target=blank really means in conjunction with a form post - from the perspective of the browser its being asked to open a new window with the results of a request carried out by a different window, which doesn't really make sense to me. Thus I'm not sure what behaviour to expect.
Without the target, the behaviour is correct - the controller instance is retained and a new page rendered in the same instance.
A link simply opens a new window with a URL to retrieve, so again that's behaving as expected. This will receive a new instance of the controller.
If you want to pass information to the newly opened window, you can either add them to the URL and store them in the controller or use directly on the page, or persist the information in an sobject and tell the new page the sobject id.