【问题标题】:JSF FileUpload doesnt work when using ui:define [duplicate]使用 ui:define [重复] 时 JSF FileUpload 不起作用
【发布时间】: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


【解决方案1】:

好的。感谢@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/a/20617462/2295729

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-16
    • 2013-08-29
    • 2014-01-30
    • 2013-08-18
    • 1970-01-01
    • 2014-05-21
    • 1970-01-01
    • 2018-07-21
    相关资源
    最近更新 更多