Thursday 21 February 2013

ADF: Show FacesMessege or we can say PopUp Message in ADF

Hello all,

This is a very basic post on ADF. This is about how we can show notification Messages. For showing Notification Messages in ADF page we use FacesMessage Component. This component can be used to show many type of message. 

Here is the code to show FacesMessage :


FacesMessage message = new FacesMessage("Record Saved Successfully!");   
      message.setSeverity(FacesMessage.SEVERITY_INFO);   
      FacesContext fc = FacesContext.getCurrentInstance();   
      fc.addMessage(null, message); 

And the message will come like :


You can change the severity of the message and show different kind of Message.

So the above code will show the facesMessage in a popup.

You can also attach this message to a component , for example you want a show a facesMessage attached to a inputText.
For doing so all you need is the id of the component.

For the above create a binding for the component in the bean.



 FacesContext.getCurrentInstance().addMessage(this.getTextCompBind().getClientId(), msg);

You can see the facesMessage attached to the component now.


this.getTextCompBind().getClientId()

The above code fetches the Id of the component which is defined in the id attribute of the component. If you know the id of the component you can put it directly as a string. In this case you have used a inputtext so you can use the id like "it1".

If you want to see a sample , click here : FacesMessageTest.jar

No comments:

Post a Comment