Let us try to understand Rendered, ReRender and RenderAs in visualforce:
A visualforce component in a vf page can be displayed or hidden by using rendered attribute. Rendered is bound to a boolean variable in controller which can be switched between true and false making the vf component display or hide depending on boolean value.
As an example:
Here lower page block is given rendered that is bound to a boolean variable "ShowpageBlockFlag". Initially (in constructor) this variable is set to false which hides the lower page block.
Once we click the command button, "ShowBlockMethod" method is called where this boolean is set to true and hence the lower page block gets displayed.
Rerender is used to refresh a particular section of the visualforce page. We have to just mention the id of the page section (in the Rerender attribute) that needs to be refreshed.
In the follwoing example Clicking of the command button "Refresh Lower Page Block" refreshes the lower page block.
Initially when the page is loaded the output string value is set in constructor as "Test value set in constructor".'
When the button is pressed method "ShowBlockMethod" is called where "OutPutString" value is changed also lower page block is refreshed and hence the new value is displayed in the lower page block.
rerender="pgblckID" statement in command button indicates that the page block section with id ="pgblckID" should be refreshed when button is pressed. Only Lower page block is refreshed rest of the page remains as it is.
A single Rerender attribute could be used to refresh many sections of the page. For example: reRender= "pgblck1, pgbcl2"
This is used with page component and renders the page in the specified format. Currently only pdf format is supported.
Following page will give output in pdf form /render as pdf.
Article 1** Article 2** Article 3** Article 4** Article 5** Article 6** Article 7** Article 8** Article 9 ** Article 10
Click For : Salesforce Interview Question And Answers