How do I able to fetch all the messages with SEVERITY is ERROR only.
I tried:
Iterator<FacesMessage> messages = facesContext.getMessages(clientId);
while (messages.hasNext()){
if(messages.next().getSeverity().toString()=="ERROR 2")System.out.println(messages);
}
Is this th right way? It doesnot intercept messages with ERROR severity.
Any help would be highly appreciated.
The comparison is wrong. You cannot (reliably) compare Strings on its content with
==. When comparing objects with==, it would only returntrueif they are of the same reference, not value as you seem to expect. Objects needs to be compared withObject#equals().But you can compare constants with
==. TheFacesMessage.Severityvalues are all static constants. You should rather just compareSeveritywithSeverity. Also the sysout is wrong, it is printing the iterator instead of the sole message.This should work: