Having 2 forms, need only 1 submit button:
<h:form>
<h:panelGrid columns="2">
<h:outputText value="#{msgs.shortDescription}"/>
<p:inputText value="#{fileBean.shortDescription}" required="true"/>
<h:outputText value="#{msgs.longDescription}"/>
<p:inputTextarea value="#{fileBean.longDescription}" required="true"/>
<h:selectOneMenu value="#{enumRegistration.selectedRegion}">
<f:selectItems value="#{enumRegistration.regionList}"/>
<f:ajax listener="#{enumRegistration.selectCity}" render="citiesmenu"/>
</h:selectOneMenu>
<h:commandButton value="Submit" action="#{fileBean.updateAd}"/>
</h:panelGrid>
</h:form>
<h:form enctype="multipart/form-data">
<p:fileUpload value="#{fileBean.file}" mode="advanced"
fileUploadListener="#{fileBean.handleFileUpload}"
required="true" allowTypes="/(\.|\/)(gif|jpe?g|png)$/"
requiredMessage="You must upload a file"/>
<p:commandButton value="Submit" ajax="false"/>
</h:form>
How to have only 1 submit button?
One option would be to enclose both within one form… Is it really the best option to have multipart/form-data on a regular form too?
Put all the fields in just a single form. It won’t break anything, and having two forms is bad due to:
1) The browser expects that after submitting the form, it will receive the data for loading a new page (in the current frame or in another). Making him send the second form after the first may result in errors.
2) JSF expects that the POST means that a new page/view is ready. Following POSTs from the same page might be ignored.
3) 1 & 2 are not true if you use AJAX. That said, if you want to send both forms at the same time there is no sense doing it with AJAX. And, if you still do, you will have a file uploaded in a request and a form uploaded in the other, and you will have to match one with the other in the server, somehow.
4) Putting all together is well tested, tried and understood. There are thousands of pages explaining how to configure the filters, access data, etc.