【发布时间】:2017-03-21 06:01:26
【问题描述】:
嘿嘿,
我在使用 PrimeFaces (6.0) 编写 JSF 应用程序时遇到问题。问题是当我使用模板 (ui:define) 时,我的应用程序中的 FileUpload 将拒绝工作。当我在没有模板的情况下构建相同的页面(相同的结构,基本上使用模板并插入示例代码)时,它就像一个魅力。两个页面都是相同的(比较输出)但是使用模板我在浏览器控制台中收到以下警告消息:
主线程上的同步 XMLHttpRequest 已被弃用,因为它会对最终用户的体验产生不利影响。如需更多帮助,请查看https://xhr.spec.whatwg.org/。
任何想法是什么导致使用 ui:define 时出现此错误?正如我提到的,不使用模板时的输出与使用相同但没有它的工作,所以我通常排除我的代码中的错误。
我的模板看起来像这样(删除了不感兴趣的部分):
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
...
</h:head>
<h:body>
<nav>
...
</nav>
<div class="wrapper">
<header>
<div class="header-title">
...
</div>
<div class="header-navbar">
...
</div>
</header>
<div class="container">
<div id="content" class="center_content">
<ui:insert name="content">Content</ui:insert>
</div>
<footer>
...
</footer>
</div>
</div>
</h:body>
</html>
替换
<ui:insert name="content">Content</ui:insert>
与
<h:form id="fileUpoad" prependId="false" enctype="multipart/form-data">
<p:fileUpload fileUploadListener="#{fileUploadBean.uploadPhoto}" mode="advanced" update="messages" auto="true" sizeLimit="100000" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />
<p:messages id="messages" autoUpdate="true" closable="true" />
</h:form>
会起作用,但这样做:
<ui:composition template="/resources/templates/dashboard_template.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<ui:define name="title">
Dashboard
</ui:define>
<ui:define name="content">
<h:form id="fileUpoad" prependId="false" enctype="multipart/form-data">
<p:fileUpload fileUploadListener="#{fileUploadBean.uploadPhoto}" mode="advanced"
update="messages" auto="true" sizeLimit="100000" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />
<p:messages id="messages" autoUpdate="true" closable="true" />
</h:form>
</ui:define>
</ui:composition>
将导致上述错误。有什么想法吗?
【问题讨论】:
-
什么时候出现这个错误?只是加载页面?正在上传吗?
-
你看到两种情况下加载 js 文件(在浏览器开发者工具中)的区别了吗?
-
@Kukeltje 我在上传时看到了这个。
-
@Kukeltje 我确实看到了细微的差别。忘了说我用的是漂亮的脸蛋。这会导致问题吗?除了这个,其他一切都很好。
标签: jquery jsf file-upload primefaces