Web过滤器中断PrimeFaces移动视图 [英] Web filter breaks PrimeFaces mobile view

查看:96
本文介绍了Web过滤器中断PrimeFaces移动视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用PrimeFaces 3.4.2的JSF2.1 Web应用程序中,我添加了一个新网页,其中仅包含一个使用renderKitId="PRIMEFACES_MOBILE"(PFM 0.9.3)的视图.想法是,过滤器会将来自移动设备的请求重定向到此页面.不幸的是,此过滤器完全破坏了某些移动设备上的移动页面的CSS(是的,并非所有设备都受影响!).当过滤器在那里时,在受影响的设备上重定向的呼叫和直接的呼叫都将中断.滤镜关闭时,一切正常.

In my JSF2.1 web application using PrimeFaces 3.4.2, I have added a new web page containing only one view with renderKitId="PRIMEFACES_MOBILE" (PFM 0.9.3). The idea is that a filter redirects requests coming from mobile devices to this page. Unfortunately this filter is completely breaking the css of the mobile page on some mobile devices (yes, not all devices are affected!). When the filter is there, either the redirected calls and the direct ones are broken on affected devices; when the filter is off, everything works fine.

这里是网络过滤器:

public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain)
        throws IOException, ServletException {

    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse resp = (HttpServletResponse) response;

    boolean isMobile = isMobileDevice(req.getHeader("user-agent"));  // utility function

    if (!req.getRequestURI().contains("/mobile/") && isMobile) {
        resp.sendRedirect(req.getContextPath() + "/faces/mobile/index.xhtml");
    } else {
        chain.doFilter(request, response);
    }    
}

过滤器在web.xml中没有任何映射.仅存在注释@WebFilter("/*").如果注释内的路径是伪造的,则一切正常.

The filter doesn't have any mapping in web.xml. Only the annotation @WebFilter("/*") is present. When the path inside the annotation is faked, everything works well.

xhtml页面非常简单:

The xhtml page is ... fairly simple:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:pm="http://primefaces.org/mobile" >
    <h:head>
    </h:head>
    <h:body>
        <f:view renderKitId="PRIMEFACES_MOBILE">
            <pm:page title="Hello World">
                <pm:view id="main">
                    <pm:header title="Header" />
                </pm:view>
            </pm:page>        
        </f:view>    
    </h:body>
</html>

有关受影响设备的其他信息,请此处. 我没有任何关于如何调试的提示.我已经使用Firebug调查了生成的html,但无法检测到两者之间的任何区别.

Additional info about the affected devices here. I have no hint about how to debug this. I have looked into the generated html using Firebug, but wasn't able to detect any difference between the working one and the other.

推荐答案

您需要让过滤器跳过CSS/JS/图像文件上的JSF资源请求.

You need to let the filter skip JSF resource requests on CSS/JS/image files.

if (req.getRequestURI().startsWith(req.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)) {
    chain.doFilter(request, response);
    return;
}

这篇关于Web过滤器中断PrimeFaces移动视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆