Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. <p>Files List</p>
  2. <h:form prependId="false">
  3. <p:dataTable value="#{pc_ArchiveFiles.archiveFiles}" var="fs"
  4. paginator="true" rows="5"
  5. paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
  6. rowsPerPageTemplate="5,10,15">
  7. <f:facet name="header">
  8. Client Files
  9. </f:facet>
  10. <p:column>
  11. <f:facet name="header">
  12. File Name
  13. </f:facet>
  14. <h:outputText value="#{fs.fileName}" />
  15. </p:column>
  16. <p:column>
  17. <f:facet name="header">
  18. File Size
  19. </f:facet>
  20. <h:outputText value="#{fs.fileSizeInKB}" />
  21. </p:column>
  22. <p:column>
  23. <f:facet name="header">
  24. Download File
  25. </f:facet>
  26. <p:commandLink id="downloadLink" value="Download" ajax="false">
  27. <p:fileDownload value="#{pc_ArchiveFiles.downloadPDF}" />
  28. </p:commandLink>
  29. </p:column>
  30. </p:dataTable>
  31. </h:form>
  32.  
  33. @ManagedBean(value = "pc_ArchiveFiles")
  34. @RequestScoped
  35. public class ArchiveFiles extends PageCodeBase {
  36. private static final Logger logger = LoggerFactory
  37. .getLogger(ArchiveFiles.class);
  38. @Value("${archive.location}")
  39. private String repository;
  40. public List<ArchiveFile> getArchiveFiles() {
  41.  
  42.  
  43. Map<String, String> params = FacesContext.getCurrentInstance()
  44. .getExternalContext().getRequestParameterMap();
  45. subCategory = params.get("categoryName");
  46.  
  47. // Build request object
  48. ArchiveFilesRequest request = new ArchiveFilesRequest();
  49. request.setCaseWorkerId(SecurityUtil.getLoggedInUser().getLoggedUserId());
  50. request.setClientId(getSelectedConsumer().getConsumerId());
  51. request.setCategoryName(subCategory);
  52. ArchiveFilesResponse response = archiveService.getArchiveFiles(request);
  53. if((response.getResponseType() == ResponseType.SUCCESS || response.getResponseType() == ResponseType.WARNING) && response.getFileCount() > 0) { // There is at least one file
  54. archiveFiles = new ArrayList<ArchiveFile>();
  55. archiveFiles.addAll(response.getFileSet());
  56. return archiveFiles;
  57. } else {
  58. return Collections.<ArchiveFile> emptyList();
  59. }
  60. }
  61.  
  62.  
  63. public void downloadPDF() throws IOException {
  64.  
  65. FacesContext facesContext = FacesContext.getCurrentInstance();
  66. ExternalContext externalContext = facesContext.getExternalContext();
  67. HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
  68.  
  69. facesContext.responseComplete();
  70. }
  71.  
  72. <h:commandLink id="downloadLink" value="Download PDF" target="_blank" action="#{pc_ArchiveFiles.downloadPDF}" />
  73.  
  74. <p:commandButton id="downloadLink" value="Download" ajax="false" onclick="PrimeFaces.monitorDownload(start, stop)"
  75. icon="ui-icon-arrowthichk-s">
  76. <p:fileDownload value="#{fileDownloadController.file}" />
  77. </p:commandButton>
  78.  
  79.  
  80.  
  81. private StreamedContent file;
  82. public StreamedContent getFile() {
  83. return file;
  84. }
  85. public void setFile(StreamedContent file){
  86. InputStream stream = ((ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext()).getResourceAsStream("/images/optimusprime.jpg");
  87. file = new DefaultStreamedContent(stream, "image/jpg", "downloaded_optimus.jpg");
  88. }
  89.  
  90. <h:commandLink id="downloadLink" value="Download PDF" target="_blank" actionListener="#{pc_ArchiveFiles.downloadPDF}" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement