Skip to content

Use of Messages, Growls and Validation

Oleh Astappiev edited this page Oct 16, 2023 · 1 revision

Use of Messages, Growls and Validation

When to use p:growl

  • Flash messages as a result of ajax requests, like: "Resources moved", "Password changed", "Saved"
  • For error messages which require users attention, use dialogFramework instead.

Example of use

Use existing methods from ApplicationBean (usually Beans should extend it) to add growls.

addGrowl(FacesMessage.SEVERITY_INFO, "Changes_saved");

Please note, that there is no need to use getLocaleMessage("Changes_saved") for the message as it is automatically translated, just provide a message key

Never add p:growl to your page, it is already part of the main template. But you can disable it if you need.

When to use p:messages

  • For messages that appear during routing, like missing parameters, invalid data, access denied.
  • Other non-ajax messages

Example of use

Similar to p:growl, just use appropriate methods:

addMessage(FacesMessage.SEVERITY_INFO, "folderCreated", folder.getTitle());

You can use addErrorMessage to show error messages, this method also sends an email notification to us (don't use it for expected errors).

To keep messages after redirecting, use setKeepMessages(); before or after a call to addMessage (once per method is enough).

Forms

In all normal forms use (including forms with ajax submit):

  • p:message for individual fields;
  • a message on top of the form with a summary of all messages. The message is necessary for mobiles, to make sure that the error message is visible (especially important for long forms).

Example of use

<p:outputLabel for="@next" value="#{msg.full_name}:" />
<p:inputText value="#{profileBean.selectedUser.fullName}" label="#{msg.full_name}:" />
<p:message for="@previous" />

TODO: need an example of a message on top of the form, e.g. using o:messages.

Clone this wiki locally