How to remove FacesMessages from the FacesContext?
Posted
by gurupriyan.e
on Stack Overflow
See other posts from Stack Overflow
or by gurupriyan.e
Published on 2010-05-27T07:09:32Z
Indexed on
2010/05/27
7:11 UTC
Read the original article
Hit count: 1095
jsf
In my screen, I have a drop down(select box), on selection of any of the options in that drop down , i display one or more text boxes beside the select box using javascript/css - display:none and display:block. All these input controls are in the same jsf form. Each of the input controls have their own validator. The problem is suppose the user selects from selection box and doesn't input value or inputs a wrong value for , i add a custom FacesMessage in the Validator and is shown appropriately and suppose the user selects the the second time and inputs the wrong value for the then another FacesMessage is added in the validator. But Now both the Messages are shown - means - the message for and - which is wrong My assumption is that , this happens because they exist in the same form and their instances are not destroyed yet in the FacesContext and in the UIView. I decided to delete the messages this way
Iterator<FacesMessage> msgIterator = FacesContext.getCurrentInstance().getMessages();
while(msgIterator.hasNext())
{
msgIterator.next();
msgIterator.remove();
}
But this sometimes gives java.util.NoSuchElementException org.apache.myfaces.shared_impl.renderkit.html.HtmlMessagesRendererBase$MessagesIterator.next
So 2 questions :
1) What is the problem in deleting the FacesMessages this way? I am using myfaces-api-1.2.3.jar and myfaces-impl-1.2.3.jar
2) Is there a better approach to handle my scenario? I only want to show relevent messages every time a jsf request is processed
Thanks
© Stack Overflow or respective owner