Let us try to understand Rendered, ReRender and RenderAs in visualforce:
Rendered
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:
visualforce page
Controller
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
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.
Visualforce page
Controller
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"
RenderAs
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.
Visualforce page
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
Simple and Superb! Well explained Mr. Gadekar.
ReplyDeleteThank you..
DeleteWell Done... for last two days, I am going through your post and all are very simple and well explained..
ReplyDeletevery nice job! very simple to follow! thanks for sharing Mr. Gadekar.
ReplyDeletethanks,well explained..
ReplyDeletesuperb ....... could you please share you skype id or any other communication id.
ReplyDeleteSimple with easy to understand explanation and examples. Appreciate your effort.
ReplyDeletethanks everyone
ReplyDeleteSimple explaination making it to understand everyone...Thanks You
ReplyDeletevery simple and easy to understand code for beginners.. Looking forward to see your video tutorial in youtube :)..
ReplyDeleteThanks alot Mr.Gadekar
Excelent Example, thank you very much... 10/10
ReplyDeleteGreat Post and good explanation .....could you please post more examples on different topics like multiple extensions with single standard or custom controller ..Thank you in advance ....I am eagerly waiting for other posts...:)
ReplyDeleteExcellent post!
ReplyDeleteCongratulations!
awesome man!!Good work
ReplyDeleteAwesome man!!Good work.
ReplyDelete