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
Sachi7Sachi7 

Dynamic Content Type for an included VF page

I am trying to construct a VF page that lists some options(multi-select max 20) for the user to choose from and has a download button to download a report(result of a Dynamic SOQL).

 

The key thing I want to achieve here is that the main page with the list of options should not go away once the download button is clicked.

 

Created 2 VF pages. 1. Lander Page 2.Excel Generator Page. Both are controlled by same apex class so that the choices can be preserved easily.

 

Excel Generator Page had contentType as "application/vnd.ms-excell". My initial thought of including (apex:include) this page in the Lander Page and rendering it only on click of download button failed. The Lander Page while loading got rendered as excel eventhough its contentType is not mentioned in its page tag.

 

To overcome this, I thought of controlling the contentType of Excel Generator Page dynamically from the apex class with a string variable "contType". On load, it shall be "text/html" and page reference method that gets called on click of download button shall change it to "application/vnd.ms-excell" and reRender the <apex:include> tag. This also does not work. Despite the contType variable gets updated (verified in logs), the included page renders as html only (the table gets displayed) and not downloading as excel.

 

Enclosing the <apex:include> tag in a seperate <apex:form> did not work either.  Guess I was wrong in hoping different view states might solve the problem.

 

Anyone tried something like this? Suggestions & Inputs are most welcome. 

 

My backup option is to open a pop-up  and submit(POST) a form with hidden parameters using jQuery.. I am just curios to get it done with VF tags only. I would really appreciate of any other better approaches, The Lander page just should not go away.

 

~Sachi