[ https://issues.apache.org/jira/browse/MYFACES-4354?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17159097#comment-17159097 ]
Thomas Andraschko edited comment on MYFACES-4354 at 7/16/20, 10:28 AM: ----------------------------------------------------------------------- i dont think so. Also Mojarra doesn't append it, so i think its not in the specs. Its only appended if you use the NavigationHandler, to navigate to another JSF view. was (Author: tandraschko): i dont think so. Also Mojarra doesn't append it, so i think its not in the specs. > ExternalContext#redirect is not add the windowId to url params. > --------------------------------------------------------------- > > Key: MYFACES-4354 > URL: https://issues.apache.org/jira/browse/MYFACES-4354 > Project: MyFaces Core > Issue Type: Bug > Components: JSR-372 > Affects Versions: 2.3-next-M3 > Environment: MyFaces 2.3-next-M3 > PrimeFaces 9.0-SNAPSHOT (local install from > https://github.com/primefaces/primefaces) > Reporter: Jan Krpata > Priority: Major > > When I navigate to another view from standard navigation, windowId is a part > of url. > > {code:java} > action="/AnotherView.xhtml"{code} > > URL contains windowId {{...AnotherView.xhtml?jfwid=XXXX}} > > But when i redirect from code like this > > {code:java} > String requestContextPath = > facesContext.getExternalContext().getRequestContextPath(); > facesContext.getExternalContext().redirect(requestContextPath + "/myTarget"); > {code} > in my HttpServlet request does not contain a windowId parameter. > > {code:java} > @WebServlet(name = "MyServlet", urlPatterns = { "/myTarget" }) > public class MyServlet extends HttpServlet { > @Override > public void doGet(HttpServletRequest request, HttpServletResponse response) > throws ServletException, IOException { > final String windowId = > request.getParameter(ConversationConsts.WINDOW_ID_PARAM); // null > // > } > {code} > > > > The ExternalContext#redirect method should add jfwid parameter to the url if > the URL does not already contain jfwid parameter. > This patch works for me. > > {code:java} > public void redirect(String url) throws IOException > { > FacesContext facesContext = getCurrentFacesContext(); > PartialViewContext partialViewContext = > facesContext.getPartialViewContext(); > if (partialViewContext.isPartialRequest()) > { > PartialResponseWriter writer = > partialViewContext.getPartialResponseWriter(); > this.setResponseContentType("text/xml"); > this.setResponseCharacterEncoding("UTF-8"); > this.addResponseHeader("Cache-control", "no-cache"); > writer.startDocument(); > writer.redirect(url); > writer.endDocument(); > facesContext.responseComplete(); > } > else if (_servletResponse instanceof HttpServletResponse) > { > ExternalContext externalContext = facesContext.getExternalContext(); > Map<String, String> requestParameterMap = > externalContext.getRequestParameterMap(); > String windowId = > requestParameterMap.get(ResponseStateManager.CLIENT_WINDOW_URL_PARAM); > if (windowId != null) > { > url = addWindowIdIfNecessary(url, windowId); > } > ((HttpServletResponse) _servletResponse).sendRedirect(url); > facesContext.responseComplete(); > } > else > { > throw new IllegalArgumentException("Only HttpServletResponse supported"); > } > } > private String addWindowIdIfNecessary(String url, String windowId) > { > if(url.contains(ResponseStateManager.CLIENT_WINDOW_URL_PARAM + "=")) > { > return url; > } > > StringBuilder newUrl = new StringBuilder(url); > if(url.contains("?")) > { > newUrl.append("&"); > } > else > { > newUrl.append("?"); > } > newUrl.append(ResponseStateManager.CLIENT_WINDOW_URL_PARAM); > newUrl.append("="); > newUrl.append(windowId); > return newUrl.toString(); > } > {code} > > > > My settings: > {code:java} > <factory> > > <lifecycle-factory>org.primefaces.clientwindow.PrimeClientWindowLifecycleFactory</lifecycle-factory> > </factory> > {code} > {code:java} > <context-param> > <param-name>javax.faces.CLIENT_WINDOW_MODE</param-name> > <param-value>url</param-value> > </context-param> > {code} > MyFaces 2.3-next-M3 > PrimeFaces 9.0-SNAPSHOT (local install from > https://github.com/primefaces/primefaces) -- This message was sent by Atlassian Jira (v8.3.4#803005)