Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 错误在<;h:inputFile/>;ajax上载:未定义partialResponse_Jsf_Jsf 2 - Fatal编程技术网

Jsf 错误在<;h:inputFile/>;ajax上载:未定义partialResponse

Jsf 错误在<;h:inputFile/>;ajax上载:未定义partialResponse,jsf,jsf-2,Jsf,Jsf 2,应用程序需要导入excel文件(.xlsx)以填充一个数据库表。当我试图通过AJAX上传文件时,问题就出现了。验证程序从未被调用(侦听器也从未被调用)。当我试图上传文件时,JSF AJAX JavaScript文件抛出一个错误并显示在浏览器控制台中:TypeError:partialResponse未定义 我的第一个想法是这是一个错误,但我不确定。这是我的第一个JSF项目 <h:form id="travels-form" class="toolbar ui form" enctype="

应用程序需要导入excel文件(.xlsx)以填充一个数据库表。当我试图通过AJAX上传文件时,问题就出现了。验证程序从未被调用(侦听器也从未被调用)。当我试图上传文件时,JSF AJAX JavaScript文件抛出一个错误并显示在浏览器控制台中:
TypeError:partialResponse未定义

我的第一个想法是这是一个错误,但我不确定。这是我的第一个JSF项目

<h:form id="travels-form" class="toolbar ui form" enctype="multipart/form-data">
    <div class="five wide field">
        <input type="text" id="search" placeholder="Buscar..." />
    </div>
    <div class="actions">
        <div class="inline field wide">
            <h:selectOneMenu valueChangeListener="#{travelBean.filter}" >
                <f:selectItem itemValue="" itemLabel="Todas las placas"  />
                <f:selectItems value="#{travelBean.licensePlates}" var="plate"
                               itemValue="${plate}" itemLabel="${plate}" />
                <f:ajax execute="@this" render=":tblTravels" />
            </h:selectOneMenu>
        </div>
        <h:outputLabel for="excel" value="Excel" styleClass="ui positive button" />
        <h:inputFile id="excel" value="#{excelImporterBean.workbook}"
                     validator="#{excelImporterBean.validate}"
                     style="display: none">
            <f:ajax execute="@this" render="excelMessage :tblTravels"
                    listener="#{excelImporterBean.onLoadWorkbook}"/>
        </h:inputFile>
        <h:message id="excelMessage" for="excel" errorClass="error-message"/>
        <h:outputLink value="#{request.contextPath}/home/recorridos/nuevo"
                      styleClass="ui primary button">
            Registrar
        </h:outputLink>
    </div>
</h:form>
该应用程序正在以下计算机上运行:

  • Tomcat 8.0.35
  • JSF(莫哈拉)2.2.13
编辑
  • 在Firefox上,错误是:未定义partialResponse
  • 在Chrome上:无法读取未定义的属性getAttribute

    • 问题是由于重写(在PrettyFaces之前)。要解决此问题,您需要在META-INF中的
      context.xml
      文件中添加属性
      allowCasualMultipartParsing=“true”
      。示例:

      <Context path="/MyApp" allowCasualMultipartParsing="true">
        <Resource auth="Container" 
                  factory="org.jboss.weld.resources.ManagerObjectFactory" 
                  name="BeanManager" 
                  type="javax.enterprise.inject.spi.BeanManager"/>
      </Context>
      
      
      
      您是否在短时间内尝试了几种不同的JSF impls/版本?尝试清理浏览器缓存或在匿名窗口中测试。很可能您仍然在浏览器缓存中使用了旧的或不同的jsf实现的jsf.js脚本。这个问题很奇怪,我用Mojarra 2.2.1(IntelliJ的默认值)测试了一个简单的ajax上传表单,一切正常。我在POM中加入了相同的Mojarra版本,结果是一样的。这意味着我可能有逻辑错误?Mojarra 2.2.1抛出了一个新的JS错误:无法读取null的属性长度。我什么都不懂,修正了。问题是由于重写(在PrettyFaces之前)。我写了解决方案。谢谢
      <Context path="/MyApp" allowCasualMultipartParsing="true">
        <Resource auth="Container" 
                  factory="org.jboss.weld.resources.ManagerObjectFactory" 
                  name="BeanManager" 
                  type="javax.enterprise.inject.spi.BeanManager"/>
      </Context>