2/23/2011

Adding messages in Liferay(liferay-ui:success, liferay:ui:error)

Liferay offers several ways to present Messages to users. So we don´t always need to use ICEFaces and ice:message.


Showing Info Messages


Go into your Portlet Class and add the following:

SessionMessages.add(actionRequest, "your-key");


This just adds a marker into the session, that the message that is connected to that key should be displayed. To connect a key to a message, add the following to your JSP:


<liferay-ui:success key="your-key" message="your-message" />


This will create something like the following:








Showing Error Messages


Errors work in two ways: Either you add an error by using the same approach with the messages:



SessionErrors.add(actionRequest, "your-key");

<liferay-ui:error key="your-key" message="your-message" />

Or you use Exceptions (e here is an instance of some Exception class):

SessionErrors.add(actionRequest, e.getClass().getName(), e);

<liferay-ui:error exception="<%=SomeException.class%>"
message="your-message" />



If you liked this tutorial it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.