How can we delete a specific FacesMessage
from FacesContext
. Lets say I have list which contains two FacesMessages whose detail(getDetail()
) is Mandatory Fields
and Invalid Account Number
and I want to delete Mandatory Fields
FacesMessage
.
Below is my sample code :
ListIterator<?> cmessages = context.getMessageList().listIterator();
cmessages.hasPrevious();
while (cmessages.hasNext() && cmessages!=null) {
FacesMessage msg =(FacesMessage) ((cmessages.next() instanceof FacesMessage)?cmessages.next():null);
if(msg!=null){
if(msg.getDetail().equals(messageDetail)){
cmessages.next();
cmessages.remove();
}
}
}
As my above code also giving me sometimes UnsupportedOperation
exception
Below is code snippet I wrote that fixed my issue
And that
UnsupportedOperation
was reported because I was previously trying to access element unexistent element in list