With Mentawai you can easily display dynamic messages. It usually works like that: The action performs some task; adds a successful message; the browser is redirected to another action or JSP page; the success message is displayed to the user; and now if the user refreshes the page, the message disappears. An example of a dynamic message could be: "Your profile was successfully updated!".
NOTE: Some frameworks call this the flash scope.
Adding a message in the action: (flash scope)
// anywhere inside the action (that extends BaseAction) addMessage("added_ok"); // message will come from an i18n file (see internationalization) // OR addMessage("The user was successfully created!");
NOTE: The flash scope works not just with a FORWARD but also with a REDIRECT. That's the beauty of it.
Showing in the JSP page:
<mtw:outMessage> <font color="blue"><mtw:out /></font> </mtw:outMessage>
NOTE: The outMessage tag is a conditional tag, so the html inside the tag is only displayed if a message is present.
Adding general errors (non-flash scope):
// anywhere inside your action (that extends BaseAction) addError("bad_username"); // OR addError("This username is already taken!");
NOTE: It makes more sense for errors NOT to be, by default, in the flash scope so they require a FORWARD and will not work with a REDIRECT.
Displaying in the JSP page:
<mtw:outError> <font color="red"><mtw:out /></font> </mtw:outError>
NOTE: The outError tag is a conditional tag, so the html inside the tag is only displayed if an error message is present.