|
From: Timo V. <sic...@gm...> - 2004-05-06 12:36:44
|
Hello,
this might be slightly off-topic.
I used to work with the InternalResourceViewResolver for convenience
until I needed support for additional View classes (redirects in my
case). However, I did not want to map every view explicitly, as in the
countries and petclinic samples, and came up with another idea: I wrote
a simple DelegatingViewResolver which maps prefixes to ViewResolvers.
The configuration looks like this:
<bean id="defaultViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property
name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property>
<property name="prefix"><value>/WEB-INF/intranet/</value></property>
<property name="suffix"><value>.jspx</value></property>
</bean>
<bean id="redirectViewResolver"
class="de.tcv.da.customerservice.util.RedirectViewResolver"/>
<bean id="viewResolver"
class="de.tcv.da.customerservice.util.DelegatingViewResolver">
<property name="defaultResolver">
<ref local="defaultViewResolver"/>
</property>
<property name="prefixMappings">
<map>
<entry key="redirect"><ref local="redirectViewResolver"/></entry>
</map>
</property>
</bean>
Now I can have view names like "redirect:http://www.google.com",
"redirect:index.page", and "showCustomer.page" without sacrificing the
convenience of the InternalResourceViewResolver for my jspx files.
This could be easily extended to multiple InternalResourceViewResolver
instances to support more View classes, yielding view names like
"xls:customer", "pdf:customer", "jsp:index", etc. The separator is
configurable.
If it's any useful to others I can contribute my DelegatingViewResolver
and RedirectViewResolver sources.
Regards,
Timo
|