Displaying Messages and Errors
Step 3 of 3
Any messages the user should see are now stored in either SessionMessages
or
SessionErrors
. Next, you’ll make these messages appear in your JSPs.
-
In the
guestbook-web
module, openguestbook/view.jsp
. Add the following block of success messages to the top of the file, just below theinit.jsp
include statement:<liferay-ui:success key="entryAdded" message="entry-added" /> <liferay-ui:success key="entryDeleted" message="entry-deleted" />
This tag accesses what’s stored in
SessionMessages
. It has two attributes. The first is theSessionMessages
key that you provided in theGuestbookPortlet.java
class’s add and delete methods. The second looks up the specified key in theLanguage.properties
file. You could have specified a hard-coded message here, but it’s far better to provide a localized key. -
Now open
guestbook_admin/view.jsp
. Add the following block of success messages in the same spot below the include:<liferay-ui:success key="guestbookAdded" message="guestbook-added" /> <liferay-ui:success key="guestbookUpdated" message="guestbook-updated" /> <liferay-ui:success key="guestbookDeleted" message="guestbook-deleted" />
Congratulations! You’ve added useful feedback for operations in your application.
Your application is shaping up, but it is missing another important feature: permissions. Next, you’ll add permission checking for your guestbooks and entries.
Look for the next part soon!