'm working on a JSF 2 project. I have defined my login.xhtml page as the entry 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 user is logged in
@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 referenced in following style:
<link href="css/styles.css" rel="stylesheet" type="text/css"/>
Everything works well until I change the css reference style to the JSF 2 Resource handler (http://www.mkyong.com/jsf2/resources-library-in-jsf-2-0/). I have copied all my css files under a resources folder and gave library name and version number. So now I reference the css as following:
<h:outputStylesheet library="default" name="css/styles.css"/>
After the change, the login.xhtml does not render the stylesheet any more. I have a welcome.xhtml page right after login.xhtml page, which has almost identical structure except for the core content, but this page render perfectly fine. I have refreshed the login.xhtml still it does not render. But once I logged in, advance to next page, then come back to login.xhtml, then refresh, the style will get rendered. Also, if I take off the loginCheckFilter, the login.xhtml will rendered the stylesheet. So if anybody ran into the similar situation and know how to resolve it? Thanks!