My JSF Books/Videos My JSF Tutorials OmniFaces/JSF PPTs
JSF 2.3 Tutorial
JSF Caching Tutorial
JSF Navigation Tutorial
JSF Scopes Tutorial
JSF Page Author Beginner's Guide
OmniFaces 2.3 Tutorial Examples
OmniFaces 2.2 Tutorial Examples
JSF Events Tutorial
OmniFaces Callbacks Usages
JSF State Tutorial
JSF and Design Patterns
JSF 2.3 New Features (2.3-m04)
Introduction to OmniFaces
25+ Reasons to use OmniFaces in JSF
OmniFaces Validators
OmniFaces Converters
JSF Design Patterns
Mastering OmniFaces
Reusable and less-verbose JSF code

My JSF Resources ...

Java EE Guardian
Member of JCG Program
Member MVB DZone
Blog curated on ZEEF
OmniFaces is an utility library for JSF, including PrimeFaces, RichFaces, ICEfaces ...

[OmniFaces Utilities] - Find the right JSF OmniFaces 2 utilities methods/functions

Search on blog

Petition by Java EE Guardians

Twitter

joi, 13 august 2015

[OmniFaces utilities 2.2] Check faces messages existence


[OmniFaces utilities] The isEmpty() method returns true if there are no faces messages, otherwise false
[OmniFaces utilities] The isEmpty(String clientId) method returns true if there are no faces messages for the given client ID, otherwise false
[OmniFaces utilities] The isGlobalEmpty() method returns true if there are no global faces messages, otherwise false


Methods:

Messages#isEmpty() - returns true if there are no faces messages, otherwise false
See also: Faces#getContext()

Messages#isEmpty(String clientId) - returns true if there are no faces messages for the given client ID, otherwise false
See also: Faces#getContext()

Messages#isGlobalEmpty() - returns true if there are no global faces messages, otherwise false
Usage:

We can use some simple logs to understand how each of the above methods works. We suppose that we have a clientIdmyForm:myInput:

LOG.log(Level.INFO, "Messages list is empty ? {0}", Messages.isEmpty());
LOG.log(Level.INFO, "Global messages list is empty ? {0}", Messages.isEmpty(null));
LOG.log(Level.INFO, "Messages list for client Id myForm:myInput is empty ? {0}", Messages.isEmpty("myForm:myInput"));     

·         no messages

Outputs:
Messages list is empty ? true
Global messages list is empty ? true
Messages list for client Id myForm:myInput is empty ? true

·         have some global messages, no clientId specific message (no messages for myForm:myInput)

FacesContext.getCurrentInstance().addMessage(null, 
  new FacesMessage(FacesMessage.SEVERITY_INFO,"Global Info","Dummy info message!"));   

Outputs:
Messages list is empty ? false
Global messages list is empty ? false
Messages list for client Id myForm:myInput is empty ? true

·         have some messages for clientId, myForm:myInput, but no global messages

FacesContext.getCurrentInstance().addMessage("myForm:myInput", 
  new FacesMessage(FacesMessage.SEVERITY_INFO,"Not Global Info","Dummy info message!"));   

Outputs:
Messages list is empty ? false
Global messages list is empty ? true
Messages list for client Id myForm:myInput is empty ? false

·         have some messages for clientId, myForm:myInput and some global messages

FacesContext.getCurrentInstance().addMessage(null, 
  new FacesMessage(FacesMessage.SEVERITY_INFO,"Global Info","Dummy info message!"));   
FacesContext.getCurrentInstance().addMessage("myForm:myInput", 
  new FacesMessage(FacesMessage.SEVERITY_INFO,"Not Global Info","Dummy info message!"));   
    
Outputs:
Messages list is empty ? false
Global messages list is empty ? false
Messages list for client Id myForm:myInput is empty ? false

Niciun comentariu :

Trimiteți un comentariu

JSF BOOKS COLLECTION

Postări populare

Follow by Email

Visitors Starting 4 September 2015

Locations of Site Visitors