'working on a JSF 2 project. I defined my login.xhtml page as the login page in web.xml
<welcome-file-list> <welcome-file>login.xhtml</welcome-file> </welcome-file-list>
And I also have a filter to check if the user is registered
@WebFilter(filterName = "loginCheckFilter", urlPatterns={"/*"}) public class LoginCheckFilter implements Filter { @Inject private LoginStatus loginStatus; public void do Filter(...) { try{ HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse res = (HttpServletResponse) response; String path = req.getRequestURI(); if(StringUtils.isNotBlank(path) && StringUtils.contains(path, ".xhtml") && !StringUtils.endsWith(path, "login.xhtml")) { if(loginStatus == null || !loginStatus.isLoggedIn()) { res.sendRedirect(req.getContextPath() + "/login.xhtml"); } else { chain.doFilter(request, response); } } else { chain.doFilter(request, response); } }catch (Exception ex) { log.error(ex); } } .... .... }
My css files were pointed in the following style:
<link href="css/styles.css" rel="stylesheet" type="text/css"/>
Everything worked fine until I changed the css link style to the JSF 2 resource handler ( http://www.mkyong.com/jsf2/resources-library-in-jsf-2-0/ ). I copied all my css files to the resources folder and gave the library name and version number. So now I refer to css as follows:
<h:outputStylesheet library="default" name="css/styles.css"/>
After the change, the login.xhtml file no longer displays the stylesheet. I have a welcome.xhtml page right after the login.xhtml page, which has an almost identical structure, with the exception of the main content, but this page looks great. I updated login.xhtml but it does not display. But as soon as I log in, go to the next page, then go back to login.xhtml and then refresh, the style will be displayed. Also, if I remove loginCheckFilter, login.xhtml will display a stylesheet. So, if someone is faced with a similar situation and knows how to resolve it? Thanks!
source share