Foren
file download using liferay+jsf portlet bridge
Simeon Kredatus, geändert vor 11 Jahren.
file download using liferay+jsf portlet bridge
New Member Beitrag: 1 Beitrittsdatum: 08.09.12 Neueste Beiträge
Hi,
I need to let user download some attachment(file) from the server using liferay portlet with jsf bridge. I think I have few possibilities how to solve this problem:
1) use direct link to some public server directory
2) use some kind of download servlet, where the user would be redirected in case of download action.
3) I hope there is also third solution - do the same work the helper download servlet is doing from the managed bean in portlet - just write a stream into HttpServletResponse.
The first and the second solutions are working fine - but I think it is not the best way how to solve this. I'd like to make it work the way I described in the third option. I've done many attempts but I couldnt make the third solution work. So I'm asking you - is it possible to do it this way at all? If yes, please could you provide some basic proof of concept or little more information about how to do it. I tried obtaining HttpServletResponse and writing to it but nothing happenned, I also tried many other solutions of this i found on google but also it wasn't working...
Thanks for advices.
I need to let user download some attachment(file) from the server using liferay portlet with jsf bridge. I think I have few possibilities how to solve this problem:
1) use direct link to some public server directory
2) use some kind of download servlet, where the user would be redirected in case of download action.
3) I hope there is also third solution - do the same work the helper download servlet is doing from the managed bean in portlet - just write a stream into HttpServletResponse.
The first and the second solutions are working fine - but I think it is not the best way how to solve this. I'd like to make it work the way I described in the third option. I've done many attempts but I couldnt make the third solution work. So I'm asking you - is it possible to do it this way at all? If yes, please could you provide some basic proof of concept or little more information about how to do it. I tried obtaining HttpServletResponse and writing to it but nothing happenned, I also tried many other solutions of this i found on google but also it wasn't working...
Thanks for advices.
Neil Griffin, geändert vor 11 Jahren.
RE: file download using liferay+jsf portlet bridge
Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
The JSF2 way of doing this would be to create a custom ResourceHandler. The jsf2-export-pdf-portlet demo is an example of how to do this.
Maximilian Hillebrand, geändert vor 11 Jahren.
RE: file download using liferay+jsf portlet bridge
New Member Beiträge: 5 Beitrittsdatum: 17.12.12 Neueste Beiträge
My solution for solving download functionality in jsf-portlet:
- extend GenericFacesPortlet and override serveResource method with your download functionality
- in your jsf-view use portlet:resourceURL with or without params
- adjust portlet.xml <portlet-class>your.extended.GenericFacesPortlet</portlet-class>
Koffi AGHOSTO, geändert vor 9 Jahren.
RE: file download using liferay+jsf portlet bridge
Junior Member Beiträge: 67 Beitrittsdatum: 27.05.14 Neueste Beiträge
Hello Maximilian,
please, I want to know how can I give the portlet:resourceURL to <p:commandButton action="">?
Thank you in advanced,
Koffi
please, I want to know how can I give the portlet:resourceURL to <p:commandButton action="">?
Thank you in advanced,
Koffi
Maximilian Hillebrand, geändert vor 9 Jahren.
RE: file download using liferay+jsf portlet bridge
New Member Beiträge: 5 Beitrittsdatum: 17.12.12 Neueste Beiträge
Hello Koffi,
I haven't used <p:commandButton action=""> for downloading functionality. Instead I used it like this:
<portlet:resourceURL var="resourceUrl" >
<portlet:param name="fileID" value="#{uploadedFile.idUploadedFile}" />
<portlet:param name="userID" value="#{uploadedFile.userId}" />
</portlet:resourceURL>
<a href="#{resourceUrl}">
<h:outputText value="#{uploadedFile.fileName}"></h:outputText>
</a>
But perhaps you also could try putting the download functionality of the overriden serveResource into the action-Method of the command-Button.
I haven't tried this out.My download functionality in serverResource look like this:
public void serveResource(ResourceRequest request, ResourceResponse response) throws IOException {
ThemeDisplay td = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
try {
if(!td.isSignedIn())
throw new NotSignedInException("User is not signed in");
//get parameters like File-ID and User-ID
//get File from backend with parameters
byte[] file = fileToBeDownloaded.getFile(); //fileToBeDownload is an own implemented class for containing file-data
//Writing file to output
response.setContentType("application/pdf");
response.addProperty("Content-Disposition", "attachment; filename="+fileToBeDownloaded.getFileName());
OutputStream out = response.getPortletOutputStream();
out.write(file);
out.flush();
out.close();
} catch(NotSignedInException ex) {
SessionErrors.add(request, "NotSignedIn");
}
}
I haven't used <p:commandButton action=""> for downloading functionality. Instead I used it like this:
<portlet:resourceURL var="resourceUrl" >
<portlet:param name="fileID" value="#{uploadedFile.idUploadedFile}" />
<portlet:param name="userID" value="#{uploadedFile.userId}" />
</portlet:resourceURL>
<a href="#{resourceUrl}">
<h:outputText value="#{uploadedFile.fileName}"></h:outputText>
</a>
But perhaps you also could try putting the download functionality of the overriden serveResource into the action-Method of the command-Button.
I haven't tried this out.My download functionality in serverResource look like this:
public void serveResource(ResourceRequest request, ResourceResponse response) throws IOException {
ThemeDisplay td = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
try {
if(!td.isSignedIn())
throw new NotSignedInException("User is not signed in");
//get parameters like File-ID and User-ID
//get File from backend with parameters
byte[] file = fileToBeDownloaded.getFile(); //fileToBeDownload is an own implemented class for containing file-data
//Writing file to output
response.setContentType("application/pdf");
response.addProperty("Content-Disposition", "attachment; filename="+fileToBeDownloaded.getFileName());
OutputStream out = response.getPortletOutputStream();
out.write(file);
out.flush();
out.close();
} catch(NotSignedInException ex) {
SessionErrors.add(request, "NotSignedIn");
}
}
Koffi AGHOSTO, geändert vor 9 Jahren.
RE: file download using liferay+jsf portlet bridge
Junior Member Beiträge: 67 Beitrittsdatum: 27.05.14 Neueste Beiträge
Maximilian,
Thank you for your reply. I will try it today and I will tell you if it works.
Thanks,
Best regards,
Koffi
Thank you for your reply. I will try it today and I will tell you if it works.
Thanks,
Best regards,
Koffi
Koffi AGHOSTO, geändert vor 9 Jahren.
RE: file download using liferay+jsf portlet bridge
Junior Member Beiträge: 67 Beitrittsdatum: 27.05.14 Neueste Beiträge
Hello Simeon,
I'am facing the same problem with Liferay 6.2 and JSF2.0. I want to send CSV file for user for downloading but
I can't arrive to do this.
I want to ask you if you are find solution to the problem which can help me.
Thank you in advanced,
Koffi
I'am facing the same problem with Liferay 6.2 and JSF2.0. I want to send CSV file for user for downloading but
I can't arrive to do this.
I want to ask you if you are find solution to the problem which can help me.
Thank you in advanced,
Koffi
Neil Griffin, geändert vor 9 Jahren.
RE: file download using liferay+jsf portlet bridge
Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
Hi Koffi,
Do your project requirements prevent you from developing a custom ResourceHandler. The jsf2-export-pdf-portlet demo is an example of how to do this.
Kind Regards,
Neil
Do your project requirements prevent you from developing a custom ResourceHandler. The jsf2-export-pdf-portlet demo is an example of how to do this.
Kind Regards,
Neil
Koffi AGHOSTO, geändert vor 9 Jahren.
RE: file download using liferay+jsf portlet bridge
Junior Member Beiträge: 67 Beitrittsdatum: 27.05.14 Neueste Beiträge
Hello Neil,
I want to thank you for your reply. I see the jsf2-export-pdf-portlet, but I don't understand well
the mechanism. I try to implement it but I don't know how to tell my Resource handler to take
my csv file from temp repository. I build my file in temp repository of liferay tomcat and then,
I try to send the file for downloading by user.
Thanks
I want to thank you for your reply. I see the jsf2-export-pdf-portlet, but I don't understand well
the mechanism. I try to implement it but I don't know how to tell my Resource handler to take
my csv file from temp repository. I build my file in temp repository of liferay tomcat and then,
I try to send the file for downloading by user.
Thanks