I've got a p:commandLink which call to bean method, which download file using Faces servlet. It works fine until I add a p:dialog in my page (commandLink doesn't inside it)
<p:commandLink value="#{file}"
actionListener="#{bean.download(file)}"
ajax="false"
immediate="true"
process="@this"/>
Ignoring that here's process="@this"
commandLink try to process variable fileName in dialog
<p:dialog header="Edit"
widgetVar="editDialog"
modal="true">
<div>
<p:panelGrid>
<p:row style="height: 50px;">
<p:column>
<p:inputText
value="#{bean.fileName}"
validator="#{fileName.validate}"
requiredMessage="file name is not filled"
validatorMessage="file with this name already exists"/>
</p:column>
</p:row>
</p:panelGrid>
</div>
</p:dialog>
And i've got an exception:
javax.el.PropertyNotFoundException:value="#{bean.fileName}": Target Unreachable, 'null' returned null
I can't turn on ajax, because in this case file won't be downloaded
Backend:
public void download(InputStream is, String fileName) {
ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
context.setResponseContentType(context.getMimeType(fileName));
context.setResponseHeader("Content-Disposition", "attachement;filename=" + fileName);
try (OutputStream os = context.getResponseOutputStream()) {
while(is.available() > 0) {
os.write(is.read());
}
}
catch(IOException ex) {
LOG.error(ex);
}
finally {
FacesContext.getCurrentInstance().responseComplete();
}
}
How can I fix it? Without dialog everything works fine