Reputation: 12465
I have problem uploading with primefaces upload widget. After some investigation I noticed that it is sending wrong post type "url-data-encoded" as opposed to multi-patrt request. Even though my form clearly declares it :
p:dialog name= "upload" id="mapping" header="Upload Mapping File" widgetVar="mappingFileDialog" fixedCenter="true">
<h:form prependId="true" id="uploadMapping" enctype="multipart/form-data">
<p:fileUpload value="#{panaceaController.file}" mode="simple"/>
<p:commandButton id="uploadbuttom" value="Submit" ajax="true"
action="#{panaceaController.handleFileUpload}"/>
</h:form>
</p:dialog>
What happens is that the file field in the controller is null. Other thing that I guess is related is that I have multiple forms in this page, I guess primefaces submits the wrong form.
BTW if I disable ajax for the upload form, the request enctype is correct, but it doesn't invoke the action anymore?!
This is my html form:
<h:form prependId="false">
<p:dataTable id="instances" lazy="false" paginator="false" var="instance"
value="#{panaceaController.instances}">
<p:column>
<f:facet name="header">
<h:outputText value="Name"/>
</f:facet>
<h:outputText value="#{instance.name}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Directory"/>
</f:facet>
<h:outputText value="#{instance.directory}"/>
</p:column>
<p:column>
<f:facet name="header">
Options
</f:facet>
<p:commandLink async="true" update="propertiesTable" oncomplete="propertiesDialog.show();">
<h:graphicImage value="img/properties.png" />
<f:setPropertyActionListener value="#{instance}" target="#{panaceaController.instance}"/>
</p:commandLink>
<p:commandLink async="true" onclick="confirmDelete.show();" >
<h:graphicImage value="img/edit-delete.png"/>
<f:setPropertyActionListener value="#{instance}" target="#{panaceaController.instance}"/>
</p:commandLink>
<p:commandLink async="true" onclick="mappingFileDialog.show();" >
<h:graphicImage value="img/mapping.png"/>
<f:setPropertyActionListener value="#{instance}" target="#{panaceaController.instance}"/>
</p:commandLink>
</p:column>
</p:dataTable>
</h:form>
<p:dialog id="properties" header="Properties" widgetVar="propertiesDialog" fixedCenter="true">
<h:panelGroup id="propertiesTable" >
<p>
Properties for #{panaceaController.instance.directory} :
</p>
<h:form>
<p:dataTable id="propertyTable" var="propertyInstance" value="#{panaceaController.instance.properties}" paginator="false">
<p:column>
<h:outputText value="#{propertyInstance.name}"/>
</p:column>
<p:column>
<h:inputText value = "#{propertyInstance.value}" required="true"/>
</p:column>
</p:dataTable>
<h:commandButton action="#{panaceaController.saveProperties}" value="Save"/>
</h:form>
</h:panelGroup>
</p:dialog>
<h:form>
<p:confirmDialog widgetVar="confirmDelete" message="Are you sure you want to delete this Panacea instance?"
severity="warn">
<p:commandButton value="Yes" update="instances" oncomplete="confirmDelete.hide()"
actionListener="#{panaceaController.delete}" />
<p:commandButton value="Not" onclick="confirmDelete.hide()" type="button" />
</p:confirmDialog>
</h:form>
<p:dialog name= "upload" id="mapping" header="Upload Mapping File" widgetVar="mappingFileDialog" fixedCenter="true">
<h:form prependId="true" id="uploadMapping" enctype="multipart/form-data">
<p:fileUpload value="#{panaceaController.file}" mode="simple"/>
<p:commandButton id="uploadbuttom" value="Submit" ajax="false" async="false"
action="#{panaceaController.handleFileUpload}"/>
</h:form>
</p:dialog>
Upvotes: 2
Views: 4038
Reputation: 1109635
I don't have any filter set up in the web.xml
You need to configure the PrimeFaces file upload filter in web.xml
as per the PrimeFaces User Guide. Here's an extract of page 170 of the User Guide for 3.0.M4:
3.34 FileUpload
...
Getting started with FileUpload
First thing to do is to configure the fileupload filter which parses the multipart request. FileUpload filter should map to Faces Servlet.
<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>
The same applies as good for older beta versions like M1 as you have.
Upvotes: 2