My application has a modal panel where the user can upload files and choose a “document type” in a drop-down select.
I was using an <f:setPropertyActionListener> to set the document type value during the upload event, but sometimes the property is set after the upload has been processed. Probably it’s happening because another request is being generated, and this request is handled by another web container thread.
<rich:modalPanel id="attachFiles" autosized="true">
<h:form id="formUpload" enctype="multipart/form-data">
<h:selectOneMenu id="docType" value="#{myMB.docType}" required="true" >
<f:selectItems value="#{myMB.docTypesSelectItems}" />
</h:selectOneMenu>`
<rich:fileUpload id="upload" fileUploadListener="#{myMB.handleUpload}">
<a4j:support event="onupload">
<f:setPropertyActionListener value="#{myMB.docType}"
target="#{myMB.docType}" />
</a4j:support>
</rich:fileUpload>
</rich:modalPanel>
When it happens, the value of myMB.docTypeis null during the execution of myMB.handleUpload, which is not expected, since the field is supposed to be required.
Is there a way to assure that the method myMB.handleUpload is executed only after the property of docType has been set?
I don’t get you. The target is the same as the value. You’re basically setting the target’s value with self. Isn’t the value itself simply already
null?Anyway, I don’t do RichFaces, so I can’t go in detail, but I know that it’s using Flash under the covers for the upload component and that such a construction usually fires a separate (and standalone) request which doesn’t take all other HTML form parameters into account. The “normal” JSF inputs comes thereafter in a separate HTTP request. So you’re kind of lost here without bringing in some nasty JS/ajax hacks. At least, in theory.
Your best bet is to get hold of the uploaded file as a bean propery in the listener method and then process that further in the normal bean’s action method (the one attached to some
UICommandcomponent in the same form).