f-angi
12/2/2015 - 4:33 PM

Spring Interceptor to hide default Liferay error messages

Spring Interceptor to hide default Liferay error messages

	<bean id="hideDefaultLiferaySessionErrorMessageInterceptor" class="it.intesys.arag.interceptor.HideDefaultLiferaySessionErrorMessageInterceptor" />

	<bean class="org.springframework.web.portlet.mvc.annotation.DefaultAnnotationHandlerMapping">
	    <property name="interceptors">
	        <list>
	            <ref bean="hideDefaultLiferaySessionErrorMessageInterceptor" />
	        </list>
	    </property>
	</bean>
package it.intesys.arag.interceptor;

import javax.portlet.PortletConfig;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import org.springframework.web.portlet.handler.HandlerInterceptorAdapter;

import com.liferay.portal.kernel.portlet.LiferayPortletConfig;
import com.liferay.portal.kernel.servlet.SessionMessages;
import com.liferay.portal.kernel.util.JavaConstants;

public class HideDefaultLiferaySessionErrorMessageInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandleRender(RenderRequest request, RenderResponse response, Object handler)
        throws Exception {

        PortletConfig pcc = (PortletConfig) request.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
        SessionMessages.add(request, ((LiferayPortletConfig) pcc).getPortletId() + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);

        return super.preHandleRender(request, response, handler);
    }

}