-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
David Turanski opened SPR-7081 and commented
The configuration below is intended to render an Excel document for a .xls extension when the view name is "accounts/list" in a Web application. No extension, or .html should resolve to the TilesView. This works, however any non-html extension, e.g., /accounts.foo also renders an Excel document . This happens because the JAF file types map returns a media type of "application/octet-stream" for arbitrary file extensions. Thus the defaultContentType is suppressed.
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="mediaTypes">
<map>
<entry key="html" value="text/html" />
<entry key="xls" value="#{ excelView.getContentType() }" />
</map>
</property>
<property name="defaultContentType" value="text/html" />
<property name="ignoreAcceptHeader" value="true" />
</bean>
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver"/>
<bean class="org.springframework.web.servlet.view.tiles2.TilesViewResolver">
<property name="contentType" value="text/html" />
</bean>
<!-- A view that generates a Account report as an Excel spreadsheet -->
<bean id="excelView" name="accounts/list" class="rewardsonline.accounts.AccountsExcelView" />
The proposed solution is to add an ignoreJafFileTypes property. If set to true, will produce the desired effect: .xls renders the Excel document, any other type reverts to the default HTML. The proposed patch and unit tests are attached.
Attachments:
- ContentNegotiatingViewResolver.java (19.37 kB)
- ContentNegotiatingViewResolverTests.java (16.99 kB)
Referenced from: commits e6b0a1d