Liferay cleans the session thus cleans the message that i add into SessionErrors.add in an EXT plugin in Liferay 6.1

721 Views Asked by At

This question can be considered an extension of How to show error message in liferay portal?

Working on an EXT plugin in liferay 6.1 and customizing UpdateLookAndFeelAction, I am putting an error message into SessionMessages.add(request,"custom-error-msg"); but seems like the portlet lifecycle cleans the session in PortalRequestProcessor.java(Line 186) thus deleting the session message as well. A normal Your settings were saved successfull is rendered How can i stop the further execution in my custom UpdateLookAndFeelAction and render this error message on /html/portlet/portlet_css/view.jsp

I have added the <liferay-ui:error key="custom-error-msg" message="custom.error.msg" /> in view.jsp

I think i read somewhere that you i have to create a hook and customize end.jsp. Is that the right approach? Any suggestions and directions will be much appreciated.

1

There are 1 best solutions below

0
On BEST ANSWER

I had to override look_and_feel.js as following:

var saveHandler = function(event, id, obj) {
                    var ajaxResponseMsg = instance._portletMsgResponse;
                    var ajaxResponseHTML = '<div id="lfr-portlet-css-response"></div>';
                    var message = '';
                    var messageClass = '';
                    var type = 'success';
                    ***var customErrorMessage = obj.response;***

                    ***if (obj.statusText.toLowerCase() == 'ok' && obj.response != '') {
                        type = 'customError';
                    }***
                    if (obj.statusText.toLowerCase() != 'ok') {
                        type = 'error';
                    }
                    if (type == 'success') {
                        message = Liferay.Language.get('your-request-processed-successfully');
                        messageClass = 'portlet-msg-success';
                    }
                    ***else if(type == 'customError') {
                        message = customErrorMessage;
                        /*message = Liferay.Language.get('custom.error.msg');*/
                        messageClass = 'portlet-msg-error';
                    }***
                    else {
                        message = Liferay.Language.get('your-settings-could-not-be-saved');
                        messageClass = 'portlet-msg-error';
                    } 

In UpdateLookAndFeel i had to return the custom error message in json object.