嘿,嘿,
我在使用PrimeFaces (6.0)编写JSF应用程序时遇到了一个问题。问题是,当我使用模板(ui:define)时,应用程序中的FileUpload将拒绝工作。当我在不使用模板的情况下构建相同的页面时(相同的结构,基本上使用模板并插入示例代码),它就像一个护身符。这两个页面是相同的(比较输出),但是使用模板,我在browser-console中得到以下警告消息:
主线程上的同步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>将导致前面提到的错误。有什么想法吗?
发布于 2016-11-09 21:09:33
好吧。感谢@Kukeltje,我发现是漂亮的脸孔导致了这个问题。不幸的是,我不能将其作为副本(Primefaces FileUpload with PrettyFaces and JSF 2.2.3)关闭。
答案:
<?xml version="1.0" encoding="UTF-8"?>
<Context allowCasualMultipartParsing="true">
</Context>在context.xml中是必需的
https://stackoverflow.com/questions/40472878
复制相似问题