我有一个p:commandLink,它调用bean方法,使用Faces servlet下载文件。它工作正常,直到我在页面中添加一个p:对话框(commandLink不在其中)
<p:commandLink value="#{file}"
actionListener="#{bean.download(file)}"
ajax="false"
immediate="true"
process="@this"/>
忽略此处process="@this"
commandLink尝试在对话框中处理变量fileName
<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>
我有一个例外:
javax.el.PropertyNotFoundException:value="#{bean.fileName}": Target Unreachable, 'null' returned null
我无法打开ajax,因为在这种情况下文件无法下载
后端:
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();
}
}
我该如何解决?没有对话框一切正常