jsf中的ajaxified文件上传

I want to do a file upload without posting an entire form. The file upload works fine, but the whole form is submitted. This works fine when validation is correct. But when p.e. a required field is empty, the upload does not work and a error message is returned (required field missing) So i tried to ajax the file upload (ajax=true). But then the upload does nothing.

I tried a work around bu putting the file upload and other fields in different forms. This works, but the result is that data you changed in the other fields is disregarded when doing the file upload.

Any suggestions?

Here is my code I use:

<t:inputFileUpload id="fileupload" value="#{prospectDetail.upFile}" size="50" />
<h:outputLabel for="description" value="#{msg.prospectdetail_description}"/>
<mw:inputText id="description" size="40" value="#{prospectDetail.fileDescription}" />
<p:commandButton styleClass="button" value="#{msg.common_upload}" action="#{prospectDetail.upload}" ajax="false" process="@form" onbegin="busyPopup.show()" oncomplete="busyPopup.hide();"/>

It is not possible to upload files by first version of XMLHttpRequest (which is the core Ajax request controller object in JavaScript). The second version of XMLHttpRequest supports it, but this is not implemented by <p:commandButton> (and has currently low browser support).

As you seem to be using PrimeFaces already, why don't you just use its own <p:fileUpload> component? The single upload or even the auto upload examples should do it for you (don't forget to remove the MyFaces extensions filter from the web.xml after adding the PrimeFaces' file upload filter!). The PrimeFaces' <p:fileUpload> will automatically utilize XHR2 file upload whenever available.

I tried a work around bu putting the file upload and other fields in different forms. This works, but the result is that data you changed in the other fields is disregarded when doing the file upload.

If you put the bean in the view scope instead of the request scope and return null or void from action methods, then this should work.