Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Issue with serveResource
Dear all,
I am facing an issue when calling ServeResource method.
I want to make a portlet which returns an excel file when a button is pressed. The excel has to be generated each time that the button is pressed.
My problem is that the excel which is returned is always the same, the first one which is generated. Only if I remove the portlet and put it again, it generates a new excel.
Anyone has any idea of why is this happening?
I use this in serve resource method:
Any help would be very appreciated.
Thanks in advance.
Kind regards.
I am facing an issue when calling ServeResource method.
I want to make a portlet which returns an excel file when a button is pressed. The excel has to be generated each time that the button is pressed.
My problem is that the excel which is returned is always the same, the first one which is generated. Only if I remove the portlet and put it again, it generates a new excel.
Anyone has any idea of why is this happening?
I use this in serve resource method:
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
res.setContentType("application/vnd.ms-excel");
res.addProperty(HttpHeaders.CACHE_CONTROL, "max-age=3600, must-revalidate");
ResourceBundle resourceBundle = ResourceBundle.getBundle("content.Language",res.getLocale());
res.addProperty(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename="+LanguageUtil.get(resourceBundle, "excel.title")+"_"+ System.currentTimeMillis() + ".xls");
Any help would be very appreciated.
Thanks in advance.
Kind regards.
Hi Daniel G,
I implemented that funcionality in following portlet:
Notes:
In my portlet I am generating all data in doView method, storing it to document library and in serveResource method I am just getting it and sending to browser, but it could be possible to do all generation code inside serveResource
Regards,
Jorge
I implemented that funcionality in following portlet:
- serveResource of portlet, See lines 1226 to 1239: https://github.com/jorgediaz-lr/index-checker/blob/master/docroot/WEB-INF/src/jorgediazest/indexchecker/portlet/IndexCheckerPortlet.java#L1226-L1239
- OutputUtils.servePortletFileEntry, see lines 369 to 404: https://github.com/jorgediaz-lr/output-utils/blob/master/src/jorgediazest/util/output/OutputUtils.java#L369-L404
Notes:
- serveResource of portlet calls OutputUtils.servePortletFileEntry method
- In order to have a resourceId in request.getResourceId() call, you have to set it in the request during previous doView() execution, see lines 443 to 450:
- Download link is written here, see lines 240 to 250:
In my portlet I am generating all data in doView method, storing it to document library and in serveResource method I am just getting it and sending to browser, but it could be possible to do all generation code inside serveResource
Regards,
Jorge
Hi Daniel,
Your serveResource method should take care of regenerating the file whenever it's called. Is it? Not sure, from the code you posted... For that it normally would get some parameters from the caller page, so that the file would be correctly generated.
HTH
Fernando
Your serveResource method should take care of regenerating the file whenever it's called. Is it? Not sure, from the code you posted... For that it normally would get some parameters from the caller page, so that the file would be correctly generated.
HTH
Fernando
Hi all.
First of all, thanks to both of you. I was able to solve the problem with your help.
My issue was due to that I was calling the method in a wrong way, so the resource stand stuck in the server.
Thanks again!
regards
First of all, thanks to both of you. I was able to solve the problem with your help.
My issue was due to that I was calling the method in a wrong way, so the resource stand stuck in the server.
Thanks again!
regards
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™