Version 4.5.0

hirondelle.web4j.model
Interface MessageList

All Known Implementing Classes:
AppException, DAOException, DuplicateException, ForeignKeyException, MessageListImpl, ModelCtorException

public interface MessageList

List of AppResponseMessage objects to be shown to the user.

Used for error messages, success messages, or any such item communicated to the user. See displayMessages.tag in the example application for an illustration of rendering a MessageList.

If a message needs to survive a redirect, it must be placed in session scope, not request scope. Typically, successful edits to the database use a redirect (to avoid the duplicate-upon-browser-reload problem), so success messages will almost always be placed in session scope. Conversely, failure messages will usually be placed in request scope.

Design Note
The forces which WEB4J resolves are :

This item is provided as an interface because AppException needs to be both an Exception and a MessageList.


Method Summary
 void add(AppException aAppEx)
          Add all AppResponseMessages attached to aAppEx to this list.
 void add(String aErrorMessage)
          Add a simple AppResponseMessage to this list.
 void add(String aErrorMessage, Object... aParams)
          Add a compound AppResponseMessage to this list.
 boolean getIsDisplayable()
          Return true only if messages exist and getMessagesForSingleDisplay() has not yet been called.
 List<AppResponseMessage> getMessages()
          Return an unmodifiable List of AppResponseMessages.
 List<AppResponseMessage> getMessagesForSingleDisplay()
          Render the messages in a JSP.
 boolean isEmpty()
          Return true only if there are no messages in this list.
 boolean isNotEmpty()
          Return the negation of isEmpty().
 

Method Detail

add

void add(String aErrorMessage)
Add a simple AppResponseMessage to this list.

The argument satisfies the same conditions as AppResponseMessage.forSimple(java.lang.String).


add

void add(String aErrorMessage,
         Object... aParams)
Add a compound AppResponseMessage to this list.

The arguments satisfy the same conditions as AppResponseMessage.forCompound(java.lang.String, java.lang.Object...).


add

void add(AppException aAppEx)
Add all AppResponseMessages attached to aAppEx to this list.


isEmpty

boolean isEmpty()
Return true only if there are no messages in this list.

Note that this method name conflicts with the empty keyword of JSTL. Thus, isNotEmpty() is supplied as an alternative.


isNotEmpty

boolean isNotEmpty()
Return the negation of isEmpty().


getIsDisplayable

boolean getIsDisplayable()
Return true only if messages exist and getMessagesForSingleDisplay() has not yet been called.


getMessages

List<AppResponseMessage> getMessages()
Return an unmodifiable List of AppResponseMessages.

JSPs must call getMessagesForSingleDisplay() instead of this method.


getMessagesForSingleDisplay

List<AppResponseMessage> getMessagesForSingleDisplay()
Render the messages in a JSP.

JSPs must call this method when rendering messages.

This method solves the following problem. Some messages need to survive a redirect. This is implemented in WEB4J by placing the messages in session scope. However, the messages should be displayed to the user only once. So the problem arises of what to do with session-scope messages once they have been displayed.

Here, the technique used is to keep the object in session scope, but if the rendering task is performed a second time on the same messages (that is, if this method is called a second time on the same object), an empty List is returned, and no text will be rendered. This is an unusual policy for an object.

Returns:
if this is the first time this method is called, return the same result as getMessages() - otherwise, return an empty List.

Version 4.5.0

Copyright Hirondelle Systems. Published April 17, 2010 - User Guide - All Docs.