This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have a problem with prefix and suffix mapping. When I use prefix-mapping
my facelets configuration does not work. I get the error:
javax.servlet.ServletException: Error Parsing /welcomeJSF.jsp: Error Traced[line: 1] The markup in the document preceding the root element must be well-formed.
When I use suffix-mapping
the servlet works but I have a filter problem.
My filter proofes which page is requested by calling the HttpServletRequest method getPathTranslated(). With prefix I get extra path information so I can check if the requested page is the login page:
but with suffix-mapping getPathTranslated always returns NULL.
Could someone please help me, either how to set up facelets with prefix-mapping or when I use suffix-mapping how can I determine within the doFilter method that the login page was requested?
First, it looks like the JSF Facelets page you are attempting to display is not well-formed XML, possibly because there's something wrong with the "<?xml ?>" Processing Instruction that must be the very first item in an XML datastream.
Secondly you have your problem in the filter itself, which I'm not sure about. I can, however, tell you that servlet filters don't behave any different for JSF requests than for non-JSF requests, and that the filter gets invoked before the FacesServlet gets the URL and picks it apart.
You're looking for a JSP page URL. I hope that's what you intended to look for.
An IDE is no substitute for an Intelligent Developer.
Joined: Dec 11, 2008
thanks for your reply. The login page is not well formed as it is a normal jsf page and not a facelets page. With suffix-mapping this is not a problem, the page gets displayed. But when I change to prefix I get the error message. The same happens when I change the welcome-file to forward.jsp. Isn't it possible to mix facelets/normal jsf pages with prefix?
"Prefix mapping" and "suffix mapping" are kind of artificial definitions. If you'll notice, the actual element name is "URL Pattern". Meaning that the container will attempt to match all incoming URLs against that pattern, and those that match are routed to the designated target. Or in your case, targets, since you're using the same URL pattern to select for the filter and to route to the FacesServlet. Which is OK if you don't want to filter the non-JSF URLs like image requests and so forth.