I have a ServletFilter that I want to use to put my app in maintenance mode by forwarding and I even tried including a facelet page but either way I can not get the facelet page to include the resources (images, css)
I know of this question Browser can't access/find relative resources like CSS, images and links when calling a Servlet which forwards to a JSP , but that answer is using a jsp page and doesn't use h:head h:body, so the things I have tried from that post haven't gotten it to work.
public class OfflineFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
LocalTime now = LocalTime.now();
LocalTime start = LocalTime.parse("06:45:00");
LocalTime stop = LocalTime.parse("07:00:00");
// Want to go into maintenance mode every morning between 6:45 and 7:00 am
if (now.isAfter(start) && now.isBefore(stop)) {
// ((HttpServletResponse) response).sendRedirect(((HttpServletRequest) request).getContextPath() + "/maintenance.xhtml");
request.getRequestDispatcher("maintenance.xhtml").forward(request, response);
// request.getRequestDispatcher("maintenance.xhtml").include(request, response);
} else {
chain.doFilter(request, response);
}
}
}
maintenance.xhtml
<h:head>
<title>Maintenance</title>
<h:outputStylesheet name="#{pageContext.request.contextPath}/css/screen.css" />
</h:head>
<h:body>
<h:outputStylesheet name="#{pageContext.request.contextPath}/css/screen.css" />
test 0<img src="/AppName/resources/gfx/bug.png" />
test 1<h:graphicImage styleClass="bug_logo" name="gfx/bug.png" />
test 2<h:graphicImage styleClass="bug_logo" name="/gfx/bug.png" />
test 3<h:graphicImage styleClass="bug_logo" name="resources/gfx/bug.png" />
test 4<h:graphicImage styleClass="bug_logo" name="#{pageContext.request.contextPath}/gfx/bug.png" />
<p:clock pattern="HH:mm:ss a" mode="server" />
even using just plain html I couldn't get things to work.
Also, I don't even think a Primefaces stylesheet is loaded either for my clock widget.
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui" xmlns:o="http://omnifaces.org/ui"
xmlns:of="http://omnifaces.org/functions">
Edit
looking at the pages source I see <img src="/AppName/javax.faces.resource/gfx/bug.png.xhtml"
But my filter is matching *.xhtml
Origianlly I was matching url /*
changing to *.xhtml
fixed things in plain html page but still can't get a facelet to work.
<filter-mapping>
<filter-name>OfflineFilter</filter-name>
<url-pattern>*.xhtml</url-pattern>
</filter-mapping>
So there is the problem, <h:graphicImage
is tacking on the .xhtml to all my resources and they are getting excluded.