Hi all,
I am currently working through the Spring Finance Manager example as created by Stefan of the Spring team.
Tutorial located at:
http://stsmedia.net/series/spring-finance/
Towards the end of Stefans tutorial he introduces a useful way of performing content negotiation like so:
As my application uses Tiles I have slightly modified this to be:Code:<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver" p:order="1"> <property name="mediaTypes"> <map> <entry key="xml" value="application/xml"/> <entry key="json" value="application/json"/> </map> </property> <property name="defaultViews"> <list> <bean class="org.springframework.web.servlet.view.xml.MarshallingView"> <property name="marshaller"> <bean class="org.springframework.oxm.xstream.XStreamMarshaller" p:autodetectAnnotations="true" /> </property> </bean> <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" /> </list> </property> </bean> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" p:order="2"/>
(Might be useful for readers)
However I have noticed that with both mine and Stefan's example that if you want to invoke the normal Web view you have to add .html to your urls.Code:<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver" p:order="1"> <property name="mediaTypes"> <map> <entry key="xml" value="application/xml"/> </map> </property> <property name="defaultViews"> <list> <bean class="org.springframework.web.servlet.view.xml.MarshallingView"> <property name="marshaller"> <bean class="org.springframework.oxm.xstream.XStreamMarshaller" p:autodetectAnnotations="true" /> </property> </bean> </list> </property> </bean> <bean id="viewResolver" class="org.springframework.js.ajax.AjaxUrlBasedViewResolver" p:order="2" > <!-- <property name="viewClass" value="org.springframework.webflow.mvc.view.FlowAjaxTilesView"/> --> <property name="viewClass" value="my.spring.view.AjaxTiles21View"/> </bean>
So if you visit http://localhost:8080/FinanceManager/person.xml or http://localhost:8080/FinanceManager/person they both render the XML views - however if you were to visit http://localhost:8080/FinanceManager/person.html you would see the normal JSP view.
Other than UrlRewriting is there anyway to avoid this as I would like people to simply be able to go to http://localhost:8080/FinanceManager/person to see web views.
As a side note I have been testing this using the Google Chrome browser in case that makes any odds such as the accept header being different?
Eggsy


Reply With Quote
