简体   繁体   English

登录后不会触发PrimeFaces 3.0M4 fileUpload

[英]PrimeFaces 3.0M4 fileUpload doesn't fire after Login

After a lot of effort I got PrimeFaces 3.0M4 working on Tomcat 7.0.2 with Mojarra 2.1.3. 经过大量的努力,我让PrimeFaces 3.0M4在Mojarra 2.1.3和Tomcat 7.0.2上运行。 The upload bean fires if I present the upload feature before login but doesn't fire if I login and then come for the file upload. 如果我在登录之前提供了上传功能,则上载bean会触发,但是如果我登录然后上传文件,则不会触发。 My filter definition is as follows: 我的过滤器定义如下:

    <filter>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
        <init-param>
            <param-name>thresholdSize</param-name>
            <param-value>2097152</param-value>
        </init-param>
        <init-param>
            <param-name>uploadDirectory</param-name>
            <param-value>c:\temp\</param-value>
        </init-param>     
    </filter>
    <filter-mapping>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>
   <!-- Faces Servlet -->
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- Faces Servlet Mapping -->
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>

The login returns to the same page that holds the upload component. 登录名返回到包含上载组件的页面。 Infact I have two forms in the same Facelet defined as follows: 实际上,我在同一Facelet中有两种形式,定义如下:

<h:form id = "loginForm">
  <h:panelGrid columns="6" rendered="#{loginBean.loginSectionVisible}">

    <h:messages errorClass="errorMessage" infoClass="infoMessage"
                            warnClass="warnMessage"></h:messages>

    <h:outputText value="Username : "></h:outputText>
    <h:inputText id="username" value="#{loginBean.username}"></h:inputText>

    <h:outputText value="Password : "></h:outputText>
    <h:inputSecret id="password" value="#{loginBean.password}"></h:inputSecret>
    <h:commandButton value="Submit" action="#{loginBean.login}" type="submit"></h:commandButton>
  </h:panelGrid>    
</h:form>
<h:panelGrid columns="1" rendered="#{loginBean.uploadSectionVisible}">
  <h:form enctype="multipart/form-data" prependId="false">
    <p:fileUpload fileUploadListener="#{fileUploadBean.handleFileUpload}"
                                    mode="advanced" 
                                    update="messages"
                                    sizeLimit="100000" 
                                    allowTypes="/(\.|\/)(gif|jpe?g|png)$/"/>
    <p:growl id="messages" showDetail="true"/>
  </h:form>

I am almost certain that it has something to with the Filter. 我几乎可以肯定,它与过滤器有关。 Any ideas? 有任何想法吗? Would be much appreciated. 将不胜感激。

<h:panelGrid columns="1" rendered="#{loginBean.uploadSectionVisible}">
  <h:form enctype="multipart/form-data" prependId="false">

Whether the upload form is processed depends on the outcome of #{loginBean.uploadSectionVisible} which you have there in the rendered attribute of a parent component. 是否处理上载表单取决于#{loginBean.uploadSectionVisible}的结果,该结果在父组件的rendered属性中具有。 You seem to be requiring that the user is logged in in order to display the upload form. 您似乎要求用户登录才能显示上载表单。 It will work if the #{loginBean} is in the session scope and you aren't doing any business logic in the getter method. 如果#{loginBean}在会话范围内,并且您没有在getter方法中执行任何业务逻辑,则它将起作用。 But it will fail if the #{loginBean} is in request scope and/or you are doing the business logic based on request parameters. 但是,如果#{loginBean}在请求范围内和/或您正在基于请求参数进行业务逻辑,它将失败。

You need to represent the logged-in user by a separate managed bean which is put in the session scope and fix the rendered attributes something like follows where #{user} is the session scoped bean representing the logged-in user: 您需要用一个单独的托管bean代表登录用户,该托管bean放在会话作用域中,并修复呈现的属性,如下所示,其中#{user}是代表登录用户的会话作用域bean:

<h:form ... rendered="#{not user.loggedIn}">
    ...
    <h:commandButton action="#{login.submit}" ... />
</h:form>
<h:form ... rendered="#{user.loggedIn}">
    <p:fileUpload fileUploadListener="#{upload.handle}" ... />
</h:form>

See also: 也可以看看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM