Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show error message in liferay portal?

How to show error message in liferay portal? I read on liferay.com site that for show error message I can use liferay-ui:error tag from tag library, but it's not working, how to use it?

like image 611
test1604 Avatar asked Jun 14 '12 11:06

test1604


1 Answers

You are right in about "liferay-ui:error" tag so on your JSP you will have:

<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<liferay-ui:error key="some-error" message="Your error message goes here!" />

Then in your Java code you will need either the RenderRequest or ActionRequest normally however any type of HTTPServletRequest or PortletRequest can also be used. Then you pass your request object to the static SessionErrors.add() method, like so:

SessionErrors.add(actionRequest, "some-error");

Then error will appear next time the portlet enters it's Render Phase.

Also another variation of the tag would be:

<liferay-ui:error exception="<%= SomeException.class %>" message="This is Some Error" />

With the SessionErrors code like:

try {
    // ... your code which throws the exception goes here
} catch(SomeException se) {
    SessionErrors.add(actionRequest, se.getClass().getName());
}

You can check the full SessionErrors JavaDoc here: http://docs.liferay.com/portal/6.1/javadocs/com/liferay/portal/kernel/servlet/SessionErrors.html

Any questions, just leave a comment!

like image 159
Jonny Avatar answered Sep 21 '22 13:09

Jonny