• Post Reply Bookmark Topic Watch Topic
  • New Topic

Rearrange Order of Messages in FacesMessages  RSS feed

 
ayzed young
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Can anyone help me how to rearrange order of message in FacesMessages.



Thanks.

 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FacesContext.getMessages() returns an abstract Iterator. That means, that although messages are considered to be in a definite order, you have no certain knowledge of what internal mechanisms actually hold the messages.

In the JSF2 api docs, it is stated that the messages are returned in the order that they were added to the FacesContext. Since there's no guarantee of internal behavior, that means the only way you can control the order of return is to control the order in which the messages were added. I suppose you could keep your own internal collection of FacesMessages, then add them in your preferred sequence to the FacesContext.

However, FacesMessages aren't really suitable for all occasions. They're primarily designed for fairly short informational sequences, such as validation errors on controls. For more elaborate messages such as multiple-line messages, possibly with style formatting, you should consider just adding a display area to the page and returning the messages as properties.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!