在我使用 PrimeFaces 3.4.2 的 JSF2.1 Web 应用程序中,我添加了一个新网页,其中仅包含一个视图renderKitId="PRIMEFACES_MOBILE"
(PFM 0.9.3)。这个想法是过滤器将来自移动设备的请求重定向到此页面。不幸的是,这个过滤器完全破坏了某些移动设备上移动页面的 CSS(是的,并非所有设备都会受到影响!)。当过滤器存在时,受影响的设备上的重定向呼叫和直接呼叫都会被破坏;当过滤器关闭时,一切正常。
这里是网络过滤器:
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("/*")
存在。当注释内的路径是伪造的时,一切正常。
xhtml 页面......相当简单:
<?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,但无法检测到工作的 html 和另一个之间的任何差异。
您需要让过滤器跳过 CSS/JS/图像文件上的 JSF 资源请求。
if (req.getRequestURI().startsWith(req.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)) {
chain.doFilter(request, response);
return;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)