Using caf_h:formattedMessages

Hi Guys,

I would like to use caf_h:formattedMessages tag to display formatted messages. But, I’m seeing weird behavior with this tag. The details are as below.

I have a porltet (PortletA) where two pages (pageA and pageB) are imported into it. Only one page will be visible based on a navigation menu selection.

Page A and Page B both have caf_h:formattedMessages tags. The formatted messages were initialized distinctly in the corresponding backing beans.

With the above setup I expected Page A and Page B to display the distinct formatted messages in the corresponding pages. (i.e., one message in each page)

But, what I’m seeing is that Page A displayed the messages that were set in both the pages backing beans and the messages are displayed duplicated. In addition to this, Page B doesn’t display the formatted message at all.

Attached sample web app depicting this issue. Can you please advise what need to be corrected in this web app and how should this tag caf_h:formattedMessages be used to see the expected behavior mentioned above.

webMethods version - 9.8 (open CAF)

Kind regards,
Raj (83.6 KB)

It appears to be working correctly as both of your views are imported into the component tree and rendered on the initial page load. So it should display the messages using the first matching “message” control it finds as your sample appears to do.

If you want finer control over which messages are displayed by each message control, you could try the caf_h:specificFormattedMessages tag and specify that you want to display the messages associated with specific controls.

For example, to only display the messages associated with the "id=“pageAMessageId” control it may look something like this:

<caf_h:specificFormattedMessages id="pageAMessageId" redisplay="false" for="pageAMessageId" />

Hi Eric,

Thanks for your reply.

  1. I specified the client control id to which this message should be added to. Per the above does it mean this tag ignores the client id specified and go with the first matching ‘message’ control it finds in the component tree?
getFacesContext().addMessage((String) getClientIds().getValue("pageAMessageId"),
				new FacesMessage("Page A Faces message"));
  1. Also, I can’t see this info in the documentation for this tag caf_h:formattedMessages, where can I find it?

  2. I have now used caf_h:specificFormattedMessages tag, specified the control id. Now the messages are displayed in the relevant pages (good), but they are displayed duplicated (not good). May I know if it is it’s expected behavior? I expected it to display the message only once. Attached sample web app that depicts this behavior.

  3. Also, how is the tag caf_h:specificFormattedMessages different to caf_h:formattedMessage (Please note it is not formattedMessages). Per the documentation, looks like they both do the same thing. (i.e., allow to associate message with specific controls).

Kind regards,
Raj (83.7 KB)

  1. All the FacesContext#addMessage call does is stash the FacesMessage object into a in-memory map on the FacesContext object for use later. Later during the render phase of the JSF lifecycle, the renderer for each of the controls that display messages will get the set of messages from the FacesContext and display them. So when considering which “message” control will display a specific message it just depends on the value of the “redisplay” control attribute and the order that the controls were rendered to the response writer.

  2. The CAF Tag Library Reference is the only documentation that is available. If something isn’t clear then you may make a proposal to improve that documentation in brainstorm @ for consideration in a future release.

  3. I don’t have time to check right now, but can you confirm that the code that added the message to the FacesContext was invoked only once? If that is the case and it is still displaying the each message more than once, the you should open a formal support ticket to get the bug fixed.

  4. caf_h:formattedMessage displays only a single message. It is the formatted equivalent of the standard h:message tag. The caf_h:specificFormattedMessages is different in that it will display all the messages instead of just the first one.