Portlet Application redirection from within Filter

I need to redirect to a view/alias from a Filter based on a value in the Session. Logic wise, I know I am able to check the
Session value and get to the redirect logic. The issue is that the would-be redirect is leaving half the ‘original’ page rendered
and the url in browser doesn’t change to the redirected page. (Thus, all that is happening is a halt of rendering the current page).

It seems events/actions/filter may be very different because we using a Portlet Application & not a Web Application. We are having trouble
intercepting a point early enough in the http/jsf process that will allow us to successfully redirect.

We are using jsr176 (no Portlet Filters). Are Filters the correct way to do this?

class SessionFilter implements javax.servlet.Filter
	public void doFilter(ServletRequest servletRequest,ServerResponse servletResponse, FilterChain chain) 
		HttpServletRequest request = (HttpServletRequest) servletRequest;
		HttpServletResponse response = (HttpServletResponse) servletResponse;
		String redirectTarget = "/target.page";
		String requestURI = request.getRequestURI().toLowerCase();
		boolean shouldRedirect = !CheckUserHasDoneImportantAction();
		if (requestURI.contains("target.page")	{ chain.doFilter(request,response); return; }
		if (shouldRedirect)						{ responses.sendRedirect( redirectTarget ); return; }
		else									{ chain.doFilter(request,response); return; }

// → web.xml

		<description>Session Filter controls login & consent.</description>

Any help welcome!

You won’t be able to reliably redirect from a portlet render request since the response would typically already be partially written when it gets to you.

So you would either have to change the link to be a portlet action request where it would be safe to redirect from your portlet action handler or write some script block in the portlet output that does a client-side redirect via javascript when your condition for doing a redirect is satisfied.

For example:

window.location.href = '/target.page';