How to hide Liferay default error message

When a server-side error occur in Liferay, a default message could be shown to the user :

Sans titre

This message is displayed when an exception is not planned to be thrown in the current JSP.

If you want to understand how and when this default message is displayed, have a look at the file “/html/taglib/ui/error/end.jsp”.

Hide the default error message in a specific page

Use this snippet in the controller of your portlet when you want to hide the default error message in a specific case :

SessionMessages.add(portletRequest, PortalUtil.getPortletId(portletRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);

(If you want to understand how it works, check the code of “/html/common/themes/portlet_messages.jspf” and search “KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE”)

Hide the default error message in every page

If you want to hide this error message everywhere in the portal you just have to edit the file “taglib/ui/error/end.jsp” via a hook.

The default error message is generated in this file (this JSP is a part of the taglib “liferay-ui:error”)

Replace

<c:when test="<%= key == null %>">
  <c:if test="<%= !SessionErrors.isEmpty(portletRequest) %>">
    <div class="alert alert-error">
      <liferay-ui:message key="your-request-failed-to-complete" />
    </div>
    <%= rowBreak %>
  </c:if>
</c:when>

by

<c:when test="<%= key == null %>">
  <c:if test="<%= !SessionErrors.isEmpty(portletRequest) %>">
    <%= rowBreak %>
  </c:if>
</c:when>

One thought on “How to hide Liferay default error message

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s