Site icon Pro Liferay

How To Hide Default Error Message in Liferay

how-to-hide-default-error-message-in-liferay


This is a very short article to discuss about how to hide default error message in Liferay Portal. I have seen in many places in the online forum about this question. While handling with liferay success message or error message, Liferay always shows the default success message or error message. In this article we will focus on quick remedy to hide default message provided by Liferay. 


Hide Default Error Message:

When we try to display error message in Liferay Portlet it displays  the default message ” Your request failed to complete”. Look into the below code

In Portlet Class:

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

In JSP:

<liferay-ui:error key="error-key" message="My Custom Error Message" />

For the above code we should get error message “My Custom Error Message”. But instead, it displays the below message

Can we hide the default message? Yes we can. Below is the code to hide it. 

SessionErrors.add(actionRequest, "error-key");
SessionMessages.add(actionRequest, PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);

Hide Default Process Action Success Message:

When in our portlet we invoke process action it display the below default success message “Your request completed successfully”

We can hide the above default message by setting add-process-action-success-action to false in init section of portlet.xml. See the below code as an example 

<portlet-name>crud-example</portlet-name>
	<display-name>CRUD Example</display-name>
	<portlet-class>com.proliferay.portlet.BookPortlet</portlet-class>
	<init-param>
		<name>view-template</name>
		<value>/html/view.jsp</value>
	</init-param>
	<init-param>
		<name>add-process-action-success-action</name>
		<value>false</value>
	</init-param>
...............Other lines..............

From numbers 8 to 11, are added for hiding the default success message

Summery:

The above codes are tested in Liferay 6.2 

 

Exit mobile version