Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to use different view resolvers in spring

 
Naresh Daswani
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

We are using jsp's in our application, but for some specific situation we want the contents to get opened in PDF format. We are using internalviewresolver for jsp combining with tiles. Also I have read that we can BeanNameViewResolver for other views..can anyone tell me complete procedure how should I do that... I tried the same..created a class extending the abstractpdfview made entry for that in servlet.xml. also declared beannameviewresolver bean. But when I return the logical name of view from controller with MV. it gives error no view exist for that logical name...

Thanks
Naresh Daswani
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you give the correct name to your PDF View bean ?

For example, if you're returning a View called "pdfContent" from your controller, you have to declare your bean as:
<bean id="pdfContent" class="view.MyPdfView"/>
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
About using multiple view resolvers, just declare them in your xml file.
You should set the order property to tell Spring which resolver has priority.

 
Naresh Daswani
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I did entries like this:
<bean id="beanNameViewResolver" class=
"org.springframework.web.servlet.view.BeanNameViewResolver"/>
<bean id="pdfView" class="com.tier.uiconnect.pdfView" />

As I specified in previous post we are using Internalviewresolver also for jsp view in the same servlet.xml
and from controller I return 'pdfView' , now where I'm commiting mistake.
also when I specified order property of the resolvers, it gave error invalid property.

Thanks
Naresh Daswani
[ June 28, 2006: Message edited by: Naresh Daswani ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which version are you using ?
In 1.2, the InternalResourceViewResolver is always the last resolver in the chain, so it doesn't have an order property. Sorry, the sample I've sent was for 2.0. You don't need to set this property with only two resolvers.

So this will do :



In your controller, how did you return the ModelAndView ? Did you set the right name "pdfView" ?
 
Naresh Daswani
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for the information, I did the same as you mentioned, I returned from my controller

return new ModelAndView("pdfView","pdfBytes",pdfBytes);
where pdfBytes is byte[].

But it gave error no view found for pdfView...I think it was trying to search with internalviewresolver and was trying to find a definition in tiles definition.xml where it did not found a view for pdfView.

Thanks
Naresh Daswani
 
xsunil kumar
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am new baby to Spring so may be my suggestion may not work but any how please read it once.

You controller class is returning view name as "PdfView", now you want to genereate the Pdf based on this view name. so do below steps

1. First define you view resolver that you want to use BeanNameViewResolver like below
<bean id="nameViewResolver" class="org.springframework.web.servlet.view.BeanNameViewResolver"/>

2. Define bean pdfview as below

<bean id="PdfView" class="org.springframework.web.servlet.view.jasperreports.JasperReportsPdfView">
<property name="url" value="/WEB-INF/pdfs/test.jrxml" />
</bean>

Hope this will solve your issue.

Regards,
Sunil
 
Jason Meng
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, I also met the same issue, I fixed it by setting the order of the resolver, make the beanNameViewResolver as the first choose for views. Hope this tip can help the others.

I believe we can set multiple view resolvers in spring, like BeanNameViewResolver and InternalResourceViewResolver. And I think spring will choose the second resolver only if the first one can't recognize the view name which is passed from controller.

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-viewresolver-resolver
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic