jsf 2 response.sendRedirect is not working

守給你的承諾、 提交于 2019-12-05 19:10:32
BalusC

Some how all response.sendRedirect() calls inside either Filter (or) JSF Bean action methods are not working.

That can happen if the request is actually an ajax request. The webbrowser doesn't translate redirects on XMLHttpRequest to the main window at all. The JS code who's sending the ajax request is responsible for that. It needs either a special/different response so that the JS code understands that it needs to change the window location, or the JS code itself needs to be altered so that it can handle the response accordingly.

If the ajax request is initiated by JSF itself (e.g. <f:ajax> and so on) and the Java code is running inside the JSF context, then you should be using ExternalContext#redirect() instead. This autodetects if the current request is an ajax request and will return a special XML response which tells the JSF ajax engine to change the location of the window. If you're not inside the JSF context (e.g. inside a Filter), then you need to create this special XML response yourself as follows:

response.setContentType("text/xml");
response.getWriter()
    .append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
    .printf("<partial-response><redirect url=\"%s\"></redirect></partial-response>", url);

See also:

FacesContext.getCurrentInstance().getExternalContext().redirect(url);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!