17

I am using PrimeFaces 3.2 in my project. I wanted to know what is the difference between setting the rendered attribute of a <p:dialog> as against setting the visible attribute. When should I use either of these attributes?

Honza Zidek
  • 9,204
  • 4
  • 72
  • 118
Nikhil
  • 415
  • 2
  • 6
  • 12

2 Answers2

32

The rendered attribute is server-side and the visible attribute is client-side. The rendered attribute tells whether JSF should generate the dialog's HTML representation or not. The visible attribute tells whether HTML/CSS/JS should immediately show the dialog on browser's page load or not.

If the dialog isn't rendered, then you won't be able to display it by for example JavaScript dialogWidgetVar.show() without reloading the page or ajax-updating one of the dialog's parent components that way so that the dialog's rendered condition evaluates to true. Also the visible attribute won't have any effect if the dialog is not rendered simply because there's nothing being rendered to the resulting HTML output which could be shown/hidden by JavaScript.

If the dialog is rendered, then it is by default hidden. You can set visible to true to force it to display the dialog immediately whenever the page is opened. Or you can invoke JavaScript dialogWidgetVar.show() in some onclick or oncomplete attribute to show it.

Use the rendered attribute if you don't want to render the dialog at all, for example because it wouldn't ever be used anyway in the currently requested page composition.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I was thinking along those lines of functionality, but couldn't make sense out of it. Thanks for that; it makes sense now. – Nick Rolando Apr 07 '12 at 18:30
  • @BalusC i have one question. in richface rich:modalPanel, if i make modalPanel render = true then it's showing a modelpanel on screen. it's fine. But same thing i tryed for primefaces p:dialog. it did't work so i replace rendered with visible tag and it's working fine for p:dialog. i dont understand, for this scenario why rendered not worked for primefaces dialog. where it is working fine for richfaces modelpanel. – Jimit Tank May 02 '13 at 14:38
  • @Jimit: the equivalent of PF dialog's `visible` attribute is RF modalPanel's `showWhenRendered`. Apparently you've set that to `true` as well. – BalusC May 02 '13 at 14:43
  • @Baluc : Hi BalusC, concerning the `` can we make it responsive? Please refer to this [question](http://stackoverflow.com/questions/40259907/is-there-anyway-to-make-the-prime-faces-dialog-as-responsive) – Jad Chahine Oct 27 '16 at 13:09
2

According to the documentation for those attributes, section 3.28:

rendered: Boolean value to specify the rendering of the component, when set to
          false component will not be rendered [default value: TRUE]
visible:  When enabled, dialog is visible by default [default value: FALSE]
Óscar López
  • 232,561
  • 37
  • 312
  • 386