0

I am implementing custom JSF component renderer (namely org.primefaces.component.messages.MessageRenderer) and would like to add output new dialog to be opened when user clicks on messages.

I understand that I can just add all needed HTML / CSS / JS right within encodeEnd method by hand but that it will be a waste as we already have a Dialog component for that.

My question is: how to programmatically construct and add to output new JSF component (dialog in my case)? I assuming we can made it interact with existing elements by specifying proper attributes.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Meta
  • 425
  • 7
  • 20

1 Answers1

0

Turns out that it's quite easy:

Dialog dialog = new Dialog();
dialog.setModal(true);
// .. other parameters
dialog.encodeAll(context);

but I have resorted to jqueryUI dialog component (you need to include javascript to your page separately)

String id = "someUniqueId";
writer.startElement("div", null);
writer.writeAttribute("id", id, null);
// ... content of dialog and command link to open dialog by id
writer.endElement("div");
writer.write("<script>$('#" + id + "').dialog("{resizable : false, autoOpen: false, modal: true});\n" +
             "$('#" + id + "').parent('.ui-dialog').css('z-index', 2000);</script>");

because it is not so easy to display nested modal dialogs in PrimeFaces.

Meta
  • 425
  • 7
  • 20