Jsf message stiffness

How can I get all messages with SECURITY only ERROR. I tried:

Iterator<FacesMessage> messages = facesContext.getMessages(clientId);
while (messages.hasNext()){
    if(messages.next().getSeverity().toString()=="ERROR 2")System.out.println(messages);
}

Is it correct? It does not intercept messages with the ERROR severity.

Any help would be greatly appreciated.

+3
source share
1 answer

The comparison is incorrect. You cannot (reliably) compare strings in your content with ==. When comparing objects with ==it, it only returns trueif they have the same reference , and not a value, as you seem to expect. Objects must be compared with Object#equals().

==. FacesMessage.Severity - . Severity Severity. , sysout , .

:

Iterator<FacesMessage> messages = facesContext.getMessages(clientId);
while (messages.hasNext()) {
    FacesMessage message = messages.next();
    if (message.getSeverity() == FacesMessage.SEVERITY_ERROR) {
        System.out.println("Error: " + message);
    }
}
+8

Source: https://habr.com/ru/post/1733942/


All Articles