Question

I am doing a project for school. I am using JSF and Primefaces. But to check authorization with Servlet Filter when HTML5 file called in JSF project. Because JSF doesn't support HTML5. Project has a HTML5 page. It is necessary to login to reach this page. However, I can't open Pop-Up or Message or Growl when HTML5 file called without login.

Can I use FacesMessage in LoginFilter ?

Code:

@WebFilter(urlPatterns = {  "/design.html" , "/demodesign.html" } )
public class LoginFilter implements Filter{
@Override
public void doFilter(ServletRequest req, ServletResponse res,
        FilterChain chain) throws IOException, ServletException {

    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;
    HttpSession session = request.getSession(false);

    UserBean userBean = (UserBean) ((session != null) ? session.getAttribute("userBean") : null);
    User member = null;

    if ( !(userBean == null) )
        member = userBean.getMember();

    if (member != null) {
        chain.doFilter(request, response);
    } else {
        response.sendRedirect(welcomeURL);
    }

}
 }
Was it helpful?

Solution

Because JSF doesn't support HTML5

This is complete nonsense. JSF is just a HTML code producer. It can produce legit HTML5 code without trouble. You can just place "plain vanilla" HTML5 elements like <canvas> in a JSF page. It will just untouch it and output it as-is. All what JSF can do more for you is to wrap it in a custom/composite component like <my:canvas> so that the submitted values are immediately updated as bean properties and that you can perform validation and attach listeners on it without any additional effort.

Just rename those HTML files to .xhtml and add/use a *.xhtml mapping on the FacesServlet. This way you'll be able to use JSF components on those so-called HTML5 pages.

See also:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top