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, openguestbookwebportlet/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="guestbookAdded" message="guestbook-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
guestbookadminportlet/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" />
Note that one of the
message
values is the same for both portlets. There’s no need to write redundant messages–language keys are reusable.
Figure 1: Now the message will display the value you specified in `Language.properties`.
Congratulations! You’ve added useful feedback for operations in your application. Next, you’ll add permission checking for your guestbooks and entries.