Messages in the FacesContext

Although to insert messages of error or information in the FacesContext, can be for many something quite simple, but it can be good explaining it for those people who are beginning in JSF. In the following tutorial we are going to learn to create them and show it in our pages with ADF.

In order to insert error messages simply we must call to the static object FacesContext and accede to the present context of the page:

FacesContext facesContext = FacesContext.getCurrentInstance();


Once we have gathered the object, we must call to one of its methods that are addMessage (…), of intuitive way, thanks to javaDoc we are going to insert the values to him to the parameters that need to us:

facesContext.addMessage
    ("cadena", new FacesMessage
        (FacesMessage.SEVERITY_ERROR, "cadena", "cadena"));

If we paid attention, the FacesMessage object is the one that will generate the type to us of message which we are going to show, that can be or of error, information, warning, etc.

Now we are going to remember, that component of ADF shows the information to us generated by the FacesContext:
<af:messages>


Adding this component, when the requests arrive at Phase 6 of the life cycle, the value of the component with the messages will be setted automatically that has contained in the FacesContext.

In addition to inserting messages, the FacesContext object has other functionalities, that already we will be seeing in tutorial futures.

Tags:

Comments are closed.