Environment (JDeveloper 11.1.2.0.0, ADF Faces)
ADF Faces uses the standard JSF messaging API. JSF supports a built-in framework for messaging by allowing FacesMessage instances to be added to the FacesContext object using the addMessage(java.lang.String clientId, FacesMessage message) method. In general there are two types of messages that can be created:component-level messages, which are associated with a specific component based on any client ID that was passed to the addMessage method, and global-level messages, which are not associated with a component because no client ID was passed to the addMessage method.
in this post, I will show how to show af:message programatically.
- global level message:
To show a global level message, use this method:
public String showMessage() {
String messageText=”A prgramatic af:message”;
FacesMessage fm = new FacesMessage(messageText);
/**
* set the type of the message.
* Valid types: error, fatal,info,warning
*/
fm.setSeverity(FacesMessage.SEVERITY_INFO);
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, fm);
return null;
}
the code above will show the message in pop-up dialog as shown below.
However, you can show the global message inline with the page, what you want to do is to change the inline attribute of the af:messages in your page, this component is created automatically for you when you create a page. The inline attribute controls whether to render the message list inline with the page or in a popup window, the default value is false. Normally the messages are rendered in a pop up. If this attribute is set to true, the messages list will be rendered inline with the page. To find the af:messages, open your page in the main window, from the structure window you can find it under f:view,af:document nodes. Your global message will be shown inline with page as shown below.
- component-level message:
To show a message inline with a component (i.e. associated with a specific UI component) you need to expose the UI component in the managed bean using the Binding property, then you can use this method:
public String showMessage() {
String messageText=”A prgramatic af:message”;
FacesMessage fm = new FacesMessage(messageText);
/**
* set the type of the message.
* Valid types: error, fatal,info,warning
*/
fm.setSeverity(FacesMessage.SEVERITY_INFO);
FacesContext context = FacesContext.getCurrentInstance();
//departmentName is the binding property for our field.
context.addMessage(getDepartmentName().getClientId(context), fm);
return null;
}
The code above will show the message associated with department name field as shown below:
This example works perfectly for me but how to I clear the message?
What do you mean by clearing the message?
I am working in 10g (10.1.3.5) my global af:message is embedded in the page. I can programmatically set the message just as you did above but I can not find a way to clear it.
I prefer to put you question OTN Jdeveloper and ADF Forum
https://forums.oracle.com/forums/forum.jspa?forumID=83
Hi Mohammad,
Thanx for the tutorial, I’m wondering if there is a way to customize the information message box to specific width and height, as you can see in pop-up global message above the height of the popup is big, I want to make it more smaller and center in the screen.
Regards,
Unfortunately I have no idea about that.
This question has been discussed in OTN by Chris Muir who is an Oracle ADF Product Manager.
https://forums.oracle.com/forums/thread.jspa?threadID=1060363
but it seems there is no answer until now.
It is better to re ask the question in Jdeveloper and ADF forum
https://forums.oracle.com/forums/forum.jspa?forumID=83
good luck there.
hi jabr,
when i inline property of af:message is set “true” jsf page not display on full size(it is just set on corner of browser window and whole page not display)
I did not face this problem, and works perfectly with me.
In my case if i change any property of af:message tag. jsf page not display correctly on browser.
Hello Manish, What is your Jdeveloper version?
thanks for wonderful blog and very useful solutions
can i handle the ok button on inside the af message?
You can use inline dialog, and handle the outcome from the dialog event.
check Example 15–2 Handler for dialogEvent That Deletes an Item, in web user interface guide.
http://docs.oracle.com/cd/E16162_01/web.1112/e16181/af_dialog.htm#CHDHCACB