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?
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!