You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Martin Grigorov (JIRA)" <ji...@apache.org> on 2015/02/20 22:26:11 UTC
[jira] [Resolved] (WICKET-5826) Add setContentType to DownloadLink
[ https://issues.apache.org/jira/browse/WICKET-5826?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Martin Grigorov resolved WICKET-5826.
-------------------------------------
Resolution: Won't Fix
I see no reason to add the setter.
As explained you can define the MIME types in your web.xml and the web container will use them.
> Add setContentType to DownloadLink
> ----------------------------------
>
> Key: WICKET-5826
> URL: https://issues.apache.org/jira/browse/WICKET-5826
> Project: Wicket
> Issue Type: Improvement
> Components: wicket
> Affects Versions: 6.18.0
> Reporter: Craig Jorgensen
> Assignee: Sven Meier
> Priority: Minor
> Labels: easyfix, newbie
> Original Estimate: 0.25h
> Remaining Estimate: 0.25h
>
> I am generating an excel file when the DownloadLink is clicked on. Everything worked fine when I was running locally for development (meaning Excel would automatically start and my excel file would be loaded) but when I used our webdev server, the file would get appended with an ".htm" and the browser would try to display the excel file which resulted in garbage on the screen.
> I eventually discovered that the contentType for the FileResourceStream in the DownloadLink::onClick() method was set to null and there is no way (that I know of to change it). I modified the DownloadLink slightly to allow this change. If there is a better way to handle this, I would like to know it. Otherwise, I would suggest adding my changes to the code.
> Basically, I added a private member variable.
> private String contentType = null;
> to the DownloadLink class with a getter and a setter and modified the onClick() method to allow me to set the FileResourceStream ContentType.
> @Override
> public void onClick()
> {
> final File file = getModelObject();
> if (file == null)
> {
> throw new IllegalStateException(getClass().getName() +
> " failed to retrieve a File object from model");
> }
> String fileName = fileNameModel != null ? fileNameModel.getObject() : null;
> if (Strings.isEmpty(fileName))
> {
> fileName = file.getName();
> }
> fileName = UrlEncoder.QUERY_INSTANCE.encode(fileName, getRequest().getCharset());
> IResourceStream resourceStream = new FileResourceStream(new org.apache.wicket.util.file.File(file)) {
> @Override
> public String getContentType() {
> return contentType;
> }
> };
> getRequestCycle().scheduleRequestHandlerAfterCurrent(
> new ResourceStreamRequestHandler(resourceStream)
> {
> @Override
> public void respond(IRequestCycle requestCycle)
> {
> super.respond(requestCycle);
> if (deleteAfter)
> {
> Files.remove(file);
> }
> }
> }.setFileName(fileName)
> .setContentDisposition(ContentDisposition.ATTACHMENT)
> .setCacheDuration(cacheDuration));
> }
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)