【发布时间】:2014-10-13 15:57:24
【问题描述】:
我在 web 应用中包含了一个 PDF 查看器,它在 Chrome 中运行良好。
但网页必须兼容 IE8 或更高版本。
而且,可悲的是,查看器在任何版本的 IE 中都会引发错误(总是如此友好......)
我正在使用 Primefaces 3.4.1(抱歉,我无法更改版本)
代码:
uploadedView.xhtml:(说明:向导内的逻辑分两步;第一个用于上传,第二个用于查看)
<p:wizard widgetVar="wizard" flowListener="#{fileBean.onFlowProcess}" >
<p:tab id="upload" title="Upload docs">
<p:panel header="Upload a PDF">
<p:growl id="messages" showDetail="true" />
<p:panelGrid columns="2">
<p:fileUpload id="fileUploaded" value="#{fileBean.file}" mode="simple"/>
<p:commandButton actionListener="#{fileBean.upload}" value="Upload" ajax="false"/>
</p:panelGrid>
</p:panel>
</p:tab>
<p:tab id="view" title="View the uploaded doc">
<p:panel header="View here the doc">
<p:media value="#{fileBean.streamedContent}" width="100%" height="500px" player="pdf" rendered="#{fileBean.streamedContent != null}"/>
</p:panel>
</p:tab>
</p:wizard>
fileBean.java:
@ManagedBean
@SessionScoped
public class FileBean implements Serializable{
static final long serialVersionUID = 42L;
private UploadedFile file;
private String fileName;
private StreamedContent streamedContent;
private InputStream stream;
public UploadedFile getFile() {
return file;
}
public void setFile(UploadedFile file) {
this.file = file;
}
public void upload() {
if(file != null) {
// Saving the stream after uploading
byte[] b = file.getContents();
stream = new ByteArrayInputStream(b);
stream.mark(0); //remember to this position!
streamedContent = new DefaultStreamedContent(stream, "application/pdf");
}
}
public StreamedContent getStreamedContent() throws IOException {
// Getting the stream data
if (file == null || file.getSize() == 0){
return new DefaultStreamedContent();
} else {
if (streamedContent != null)
streamedContent.getStream().reset(); //reset stream to the start position!
return streamedContent;
}
}
public String onFlowProcess(FlowEvent event) {
// Flow for wizard
if (event.getNewStep() == null || event.getNewStep().isEmpty()){
return event.getOldStep();
}
if (file == null || file.getSize() == 0) {
return "not file";
} else {
return event.getNewStep();
}
}
在 Chrome 中,服务器只显示此警告,但查看器工作正常:
ADVERTENCIA: JSF1091: no se ha encontrado ningún Tipo MIME para el archivo dynamiccontent。 Para resolverlo, agregue una asignación de tipo MIME al archivo web.xml de la aplicación。
(翻译:总而言之,动态内容中缺少MIME类型)
但在IE中,除此之外,还显示下一个:
13-oct-2014 17:52:53 org.primefaces.application.PrimeResourceHandler handleResourceRequest GRAVE:流式传输动态资源中的错误。 La expresión no puede ser nula
(翻译:表达式不能为空)
查看器会在浏览器中弹出一个弹出窗口:
文件不以'%PDF-". 等开头...
首先,我不明白为什么服务器会抛出 IE 异常。
对不起我的英语和..
您好!
【问题讨论】:
标签: jsf primefaces