掲示板
file download using liferay+jsf portlet bridge
11年前 に Simeon Kredatus によって更新されました。
file download using liferay+jsf portlet bridge
New Member 投稿: 1 参加年月日: 12/09/08 最新の投稿
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.
11年前 に Neil Griffin によって更新されました。
RE: file download using liferay+jsf portlet bridge
Liferay Legend 投稿: 2655 参加年月日: 05/07/27 最新の投稿
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.
11年前 に Maximilian Hillebrand によって更新されました。
RE: file download using liferay+jsf portlet bridge
New Member 投稿: 5 参加年月日: 12/12/17 最新の投稿
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>
9年前 に Koffi AGHOSTO によって更新されました。
RE: file download using liferay+jsf portlet bridge
Junior Member 投稿: 67 参加年月日: 14/05/27 最新の投稿
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
9年前 に Maximilian Hillebrand によって更新されました。
RE: file download using liferay+jsf portlet bridge
New Member 投稿: 5 参加年月日: 12/12/17 最新の投稿
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");
}
}
9年前 に Koffi AGHOSTO によって更新されました。
RE: file download using liferay+jsf portlet bridge
Junior Member 投稿: 67 参加年月日: 14/05/27 最新の投稿
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
9年前 に Koffi AGHOSTO によって更新されました。
RE: file download using liferay+jsf portlet bridge
Junior Member 投稿: 67 参加年月日: 14/05/27 最新の投稿
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
9年前 に Neil Griffin によって更新されました。
RE: file download using liferay+jsf portlet bridge
Liferay Legend 投稿: 2655 参加年月日: 05/07/27 最新の投稿
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
9年前 に Koffi AGHOSTO によって更新されました。
RE: file download using liferay+jsf portlet bridge
Junior Member 投稿: 67 参加年月日: 14/05/27 最新の投稿
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