【问题标题】:Primefaces p:fileUpload not working [duplicate]Primefaces p:fileUpload不起作用[重复]
【发布时间】:2014-05-04 09:37:28
【问题描述】:

我将 Primefaces4.0 与 JSF2.0 一起使用,我了解 Primefaces 的一些基础知识。 对我来说p:fileUpload 不工作,它以前工作过。不知道发生了什么 当我从文件选择器中选择任何文件时,p:fileUpload 的文件盘中没有填充任何文件。

这是我的代码:

<p:panel style="font-size:15px;" header="Upload"> 
    <p:fileUpload  fileUploadListener="#{addAgentxls.handleFileUpload}" mode="advanced" dragDropSupport="true"
                   update="messages status" sizeLimit="100000"  style="font-size:12px;" />
    <p:growl id="messages" showDetail="true"/>
    <p:outputLabel id="status" style="font-size:13px;"  value="#{addAgentxls.status }"/>
</p:panel>

类文件:

@ManagedBean(name = "addAgentxls", eager = true)
@SessionScoped
public class AddAgentUsingXLS {
    public AddAgentUsingXLS(){
    }
    public void handleFileUpload(FileUploadEvent event) {
           FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");  
           FacesContext.getCurrentInstance().addMessage(null, msg);
        } 
}

web.xml:

<!-- File Uploading Constraints -->
<filter>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>

我也看到 This 没有为我做任何事情 谷歌浏览器出现错误

Uncaught TypeError: Object [object Object] has no method 'fileupload' 
fileupload.js.xhtml?ln=primefaces&v=4.0:1

有什么价值吗?

【问题讨论】:

  • 我不确定您是否已将 enctype="multipart/form-data" 添加到您的表单中。
  • 是的,面板是在 h:form 中添加的
  • 感谢 @psi 链接帮助 BalusC 值得,我使用的是更新版本的 jQuery.js

标签: file-upload jsf-2 primefaces


【解决方案1】:

解决了..!我使用的是较新版本的 jQuery.js,它与 Primefaces 冲突

【讨论】:

    【解决方案2】:

    请考虑以下堆栈溢出链接的建议。

    In JavaScript can I make a "click" event fire programmatically for a file input element?

    同样的问题。 jQuery(".primeFacesHiddenAwayButton type=['file']").click() 在 IE 和 firefox 上运行良好(由于 Selenium 驱动程序的限制,我的 firefox 不是最新的)。无论如何,在 chrome 中,JS 按钮根本不起作用。显然,这是浏览器内置的安全功能。您可以尝试提供的链接上的建议。

    【讨论】:

      猜你喜欢
      • 2015-07-26
      • 1970-01-01
      • 1970-01-01
      • 2012-05-30
      • 2016-08-19
      • 1970-01-01
      • 2021-01-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多