Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get count of globalOnly FacesMessages better?

Tags:

jsf

jsf-2

I write a "not so correct" code to count the globalOnly messages programatically.

for (final FacesMessage message : facesContext.getMessageList()) {
    if (!message.getClass().getCanonicalName().equals("javax.faces.component.MessageFactory.BindingFacesMessage")) {
            globalOnlyMessagesCount++;
    }
}

For non-jsf developres: javax.faces.component.MessageFactory.BindingFacesMessage is a non-visible class, so instanceof doesn't work. As I found the message is a BindingFacesMessage or FacesMessage

Is there any better solution? (except I put the string literal to constant).

like image 653
azendh Avatar asked Dec 17 '25 04:12

azendh


1 Answers

Global only messages are identified by a null client ID.

So, this should do, in combination with another getter taking a client ID:

int globalOnlyMessagesCount = facesContext.getMessageList(null).size();
like image 60
BalusC Avatar answered Dec 19 '25 22:12

BalusC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!