0

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.

Community
  • 1
  • 1
dev_in_prog
  • 121
  • 1
  • 18
  • SessionErrors are handled for a portlet level. What you are trying to do is updating UpdateLookAndFeelAction file through ext and reading the error in portlet view.jsp. So, try 2nd option with and in your ext action file catch an exception and set session error SessionErrors.add(actionRequest, se.getClass().getName()); – Neeraj Gautam Jun 19 '15 at 15:11

1 Answers1

1

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.

dev_in_prog
  • 121
  • 1
  • 18