Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
Simeon Kredatus
file download using liferay+jsf portlet bridge
8 settembre 2012 2.07
Risposta

Simeon Kredatus

Punteggio: New Member

Messaggi: 1

Data di Iscrizione: 8 settembre 2012

Messaggi recenti

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.
Neil Griffin
RE: file download using liferay+jsf portlet bridge
19 settembre 2012 10.39
Risposta

Neil Griffin

LIFERAY STAFF

Punteggio: Liferay Legend

Messaggi: 2335

Data di Iscrizione: 26 luglio 2005

Messaggi recenti

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
RE: file download using liferay+jsf portlet bridge
9 febbraio 2013 6.57
Risposta

Maximilian Hillebrand

Punteggio: New Member

Messaggi: 5

Data di Iscrizione: 17 dicembre 2012

Messaggi recenti

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
RE: file download using liferay+jsf portlet bridge
27 maggio 2014 15.41
Risposta

Koffi AGHOSTO

Punteggio: Junior Member

Messaggi: 44

Data di Iscrizione: 27 maggio 2014

Messaggi recenti

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
Koffi AGHOSTO
RE: file download using liferay+jsf portlet bridge
27 maggio 2014 15.44
Risposta

Koffi AGHOSTO

Punteggio: Junior Member

Messaggi: 44

Data di Iscrizione: 27 maggio 2014

Messaggi recenti

Hello Maximilian,

please, I want to know how can I give the portlet:resourceURL to <p:commandButton action="">?

Thank you in advanced,

Koffi
Neil Griffin
RE: file download using liferay+jsf portlet bridge
27 maggio 2014 15.44
Risposta

Neil Griffin

LIFERAY STAFF

Punteggio: Liferay Legend

Messaggi: 2335

Data di Iscrizione: 26 luglio 2005

Messaggi recenti

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
Koffi AGHOSTO
RE: file download using liferay+jsf portlet bridge
27 maggio 2014 22.25
Risposta

Koffi AGHOSTO

Punteggio: Junior Member

Messaggi: 44

Data di Iscrizione: 27 maggio 2014

Messaggi recenti

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
Maximilian Hillebrand
RE: file download using liferay+jsf portlet bridge
27 maggio 2014 22.34
Risposta

Maximilian Hillebrand

Punteggio: New Member

Messaggi: 5

Data di Iscrizione: 17 dicembre 2012

Messaggi recenti

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");
}
}
Koffi AGHOSTO
RE: file download using liferay+jsf portlet bridge
27 maggio 2014 23.08
Risposta

Koffi AGHOSTO

Punteggio: Junior Member

Messaggi: 44

Data di Iscrizione: 27 maggio 2014

Messaggi recenti

Maximilian,

Thank you for your reply. I will try it today and I will tell you if it works.

Thanks,
Best regards,
Koffi