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
krishnagkrishnag 

javascript and Apex

can anybody help me how to pass the javascript values to a  controller in a visualforce page

Best Answer chosen by Admin (Salesforce Developers) 
krishnagkrishnag

looks like i found the problem.there is a limitation of render as pdf from salesforce

 

renderAsThe name of any supported content converter. Currently pdf is the only supported content converter. Setting this attribute to pdf renders the page as a pdf. Rendering a Visualforce page as a PDF is intended for pages that are designed and optimized for print. Standard components which are not easily formatted for print or contain form elements like inputs, buttons, any component that requires JavaScript to be formatted, should not be used. This includes but is not limited to, any component that requires a form element. Verify the format of your rendered page before deploying it. If the PDF fails to display all the characters, adjust the fonts in your CSS to use a font that supports your needs. For example, <apex:page renderas="pdf"> <style> body { font-family: Arial Unicode MS; } </style> Note that the pageBlock and sectionHeader components do not suppor double-byte fonts when rendered as a PDF.

All Answers

VinOKVinOK

There are a few ways of achieving this.  Here are the 2 methods that I use the most.

 

If you only need to feed data from Javascript to the controller an actionFunction is probably the best way to go. 

 

if you need to pass data back and forth from Javascript to the Controller, then I would suggest that you create an Apex:inputHidden field and bind it to a controller property.  javascript can climb into this hidden element and modify / read the values.  The controller can access this data simply as a property.  In this approach, you should ensure that you are reRendering the inputHidden VF object every time your controller is called to do something.

krishnagkrishnag

can u give me an example code or syntax to achieve this

krishnagkrishnag

ma y be i can give you my scenario you can help me ion achieving this.what is my issue. Some developer has written a html page in which the data is populated from getting the parameters from URL of the link they are clicking it.

now the same functionality they want to achieve in visualforce page.So normally i embedded the code of HTML in the visual force and tried and its working fine and it is also populating the data,(I have included the java script of that developer using <script> tags, But where the problem came is the cleint asked us to make the page render as pdf.So i inserted render as pdf on the page tag. 

 

So when it is render as pdf the input fileds are not visible in PDF.

 

Can anyone tell me is that issue in page or render as pdf  problem.

krishnagkrishnag

looks like i found the problem.there is a limitation of render as pdf from salesforce

 

renderAsThe name of any supported content converter. Currently pdf is the only supported content converter. Setting this attribute to pdf renders the page as a pdf. Rendering a Visualforce page as a PDF is intended for pages that are designed and optimized for print. Standard components which are not easily formatted for print or contain form elements like inputs, buttons, any component that requires JavaScript to be formatted, should not be used. This includes but is not limited to, any component that requires a form element. Verify the format of your rendered page before deploying it. If the PDF fails to display all the characters, adjust the fonts in your CSS to use a font that supports your needs. For example, <apex:page renderas="pdf"> <style> body { font-family: Arial Unicode MS; } </style> Note that the pageBlock and sectionHeader components do not suppor double-byte fonts when rendered as a PDF.
This was selected as the best answer
VinOKVinOK

Not sure if this information helps, but....

 

Within a controller, you can use a PageReference to retrieve the URL parameters directly.  Here's a code snippet that pulls a retUrl param out of the Url.

 

 

PageReference currPage = System.currentPageReference();
Map<String, String> params = currPage.getParameters();

String retUrl = params.get('retUrl');

 

 if you're just pulling our parameters from the url and trying to stick them into properties, you may be able to leverage this code.