Hi am trying to upload a file using primefaces which works fine when I don't have confirm dialog in the submit button. but when I add the the managed bean is not even called.
Here is my xhtml code:
<p:panel header="New Business Registration" style=" min-height: 400px">
<h:form id="upload" enctype="multipart/form-data">
<p:messages closable="true" />
<p:panelGrid columns="2">
<p:outputLabel value="Select Image"/>
<p:fileUpload mode="simple" value="#{fileUploadMBean.uploadedFile}"/>
p:outputLabel value=""/>
<p:commandButton update="upload" ajax="false" action="#{fileUploadMBean.uploadFile}" icon="ui-icon-person" value="Register New Client">
<p:confirm header="Confirm" message="Are you sure you wish to upload this file" />
</p:commandButton>
</p:panelGrid>
</h:form>
<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
<p:commandButton value="Yes" style="color: #fff;
background-color: #5cb85c;
border-color: #4cae4c;" type="button" styleClass="ui-confirmdialog-yes" icon=" ui-icon-check" />
<p:commandButton value="No" style="background-color: #d9534f; border-color: #d43f3a;" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-closethick" />
</p:confirmDialog>
</p:panel>
And my managed bean:
@ManagedBean
@ViewScoped
public class FileUploadMBean implements Serializable {
private UploadedFile uploadedFile;
public String uploadFile() throws IOException {
System.out.println("hello:"); //method not called when i use confirm dialog but when i dont use file upload is successfull
FacesContext context = FacesContext.getCurrentInstance();
if(uploadedFile==null)
{
context.addMessnage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Blank File detected", "image"));
return "";
}
//jsf file upload here
{}//upload code here which works fine without p:confirm
return null;
}
When I use
<p:commandButton update="upload" action="#{fileUploadMBean.uploadFile}" icon="ui-icon-person" value="Register New Client">
</p:commandButton>
The uploaded file is null;
When I disable Ajax and without like
<p:commandButton update="upload" action="#{fileUploadMBean.uploadFile}" icon="ui-icon-person" ajax="false" value="Register New Client">
</p:commandButton>
Upload is Successfull.
When I now add when ajax is disabled in the submit button the managed method is not getting invoked at all
<p:commandButton update="upload" action="#{fileUploadMBean.uploadFile}" icon="ui-icon-person" ajax="false" value="Register New Client">
<p:confirm header="Confirm" message="Are you sure you wish to upload this file" />
</p:commandButton>