Showing posts with label Liferay-UI success messages. Show all posts
Showing posts with label Liferay-UI success messages. Show all posts

Wednesday, July 31, 2013

How to override/hide Liferay default error messages?

Many people asked me this question "how we can hide or override Liferay default error message with custom messages?".



So, I thought of sharing this simple post explaining how to do this.

There are 3 ways of doing this:
1) Hide the complete portal's default error messages.(Most client don't want this but some client does.)
2) Hide the default error messages for specific portlet.
3) Hide the messages with the help of CSS.(People generally don't use this method but sometime for some specific requirement you might need this).

Let's take them one by one.

1) Hide the complete portal's default error messages.

In order to accomplish this, we need to create a hook of "end.jsp" file(html/taglib/ui/error).

end.jsp file pops liferay error messages.

Hook is a liferay functionality provided to override liferay's default functionality. You can create hook for custom jsps, language properties, services and portal properties.

 1.1) In your project create a liferay-hook.xml file with below content:
     

This will tell liferay to pick new custom "end.jsp" from custom_jsps folder.
Folder structure will be like this: /custom_jsps/html/taglib/ui/error/end.jsp
If you are using Liferay IDE then it will create the folder structure itself else create the structure and add end.jsp.
To disable the default message comment code from line 21 till line 33. Just comment that piece of code, deploy the hook and you are all set.



 
2) Hide the default error messages for specific portlet

For this we will follow the same steps for creating the hook and extending the end.jsp.
Only change will be of adding a check for our specific portlet.

In end.jsp, instead of commenting the code which we comment in the above method we will add a check for our specific portlet using portlet Id.



3) Hide the messages with the help of CSS

I actually don't recommend this approach but sometime we do need this. Basically with help of css we are hiding our error messages or success messages.
Mostly used inside specific jsps instead of making generic.

.portlet-msg-error{           display : none;}
Note:
If you don't know how to create a hook , please refer liferay wiki. It's simple and easy.
Also, refer the below link for further details on error & success messages:

Liferay error & success messages Wiki

Feel free to ask any question and Happy Learning :)