0

After a lot of effort I got PrimeFaces 3.0M4 working on Tomcat 7.0.2 with Mojarra 2.1.3. 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. 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:

<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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Macky
  • 433
  • 2
  • 9
  • 22

1 Answers1

0
<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. 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. But it will fail if the #{loginBean} is in request scope and/or you are doing the business logic based on request parameters.

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:

<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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Many thanks BaluC.Yes, my LoginBean was RequestScoped. I have made it SessionScoped.I'll move the logged in user into a separate session scoped bean. – Macky Nov 21 '11 at 03:15