在文档查看器中以主要字体显示上传的文档



>我正在研究我需要在 primeface 中使用 fileupload 组件上传文件并在同一页面上使用 documentViewer 组件显示相同文件的要求。

<h:form  enctype="multipart/form-data">
<p:fileUpload value="#{basicDocumentViewerController.file}"  mode="simple"></p:fileUpload>
<p:separator/>
<h:commandButton value="Upload file" action="#{basicDocumentViewerController.dummyAction}">
</h:commandButton>
<p:tabView>  
<p:tab title="Display content of the file">  
<pe:documentViewer id="documentViewer"  height="500" value="#{basicDocumentViewerController.content}" />  
</p:tab>  
</p:tabView>  
</h:form>

在上载操作成功完成之前,应禁用文档查看器组件或不可见。 上传操作后,内容应使用侦听器显示在文档查看器中。 你能帮忙实现这一目标吗

正如@Selaron所建议的那样。我添加了传递给渲染属性的布尔属性。仅当上传文档成功时,才会使它成为真。

下面是供参考的代码片段。

网页内容

<h:body>
<h:form  enctype="multipart/form-data">
<p:fileUpload value="#{basicDocumentViewerController.file}"  mode="simple"></p:fileUpload>
<p:separator/>
<h:commandButton value="Dummy Action" action="#{basicDocumentViewerController.dummyAction}">
</h:commandButton>
<pe:documentViewer id="documentViewer" rendered="#{basicDocumentViewerController.contentAvailable}" height="500" value="#{basicDocumentViewerController.content}" download="extensions-rocks.pdf"/>  
</h:form>
</h:body>

豆类

@ManagedBean(name = "basicDocumentViewerController")
@SessionScoped
public class BasicDocumentViewerController implements Serializable {
private static final long serialVersionUID = 1L;
private StreamedContent content;
private UploadedFile file;
private boolean contentAvailable =false;
public UploadedFile getFile() {
return file;
}
public void setFile(UploadedFile file) {
this.file = file;
}
public StreamedContent getContent() throws IOException {
if(content == null){
content=pdfDocumentGenerate();
}
return content;
}
public String dummyAction(){
System.out.println("Uploaded File Name Is :: "+file.getFileName()+" :: Uploaded File Size :: "+file.getSize());
setContentAvailable(true);
return "";
}
public void setContent(StreamedContent content) {
this.content = content;
}

public DefaultStreamedContent pdfDocumentGenerate() throws IOException {
try {
byte[] document = IOUtils.toByteArray(file.getInputstream());
return new DefaultStreamedContent(new ByteArrayInputStream(document), "application/pdf", "Actor_List");
}finally{
}
}
public boolean isContentAvailable() {
return contentAvailable;
}
public void setContentAvailable(boolean contentAvailable) {
this.contentAvailable = contentAvailable;
}
}

相关内容

  • 没有找到相关文章

最新更新