Show Message in a Dialog

Showing a message in a dialog is a common requirement and new Dialog Framework provides a way to make this easier.

Usually this can be done by placing a p:dialog on a page with a messages component inside and page author manually needs to update the messages after adding a message to request. Well, in dialog framework it is just one line of java code;

<h:form> <p:commandButton value="Show" icon="ui-icon-script" actionListener="#{dialogBean.showMessage}" /> </h:form> 1 2 3 <h:form> <p:commandButton value = "Show" icon = "ui-icon-script" actionListener = "#{dialogBean.showMessage}" /> </h:form>

package org.primefaces.examples.view; public class DialogBean { public void showMessage() { RequestContext.getCurrentInstance().showMessageInDialog(new FacesMessage(FacesMessage.SEVERITY_INFO, "What we do in life", "Echoes in eternity.")); } } 1 2 3 4 5 6 7 8 package org . primefaces . examples . view ; public class DialogBean { public void showMessage ( ) { RequestContext . getCurrentInstance ( ) . showMessageInDialog ( new FacesMessage ( FacesMessage . SEVERITY_INFO , "What we do in life" , "Echoes in eternity." ) ) ; } }

Check out the live demo on PrimeFaces Showcase. This feature will be available in Elite 3.5.8 and Sentinel (4.0).

P.S. Special thanks to PrimeFaces Team Member and my friend Thomas Andraschko for the idea, implementing this was fun.