aspose file tools*
The moose likes Other Application Frameworks and the fly likes how to use different view resolvers in spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "how to use different view resolvers in spring" Watch "how to use different view resolvers in spring" New topic
Author

how to use different view resolvers in spring

Naresh Daswani
Greenhorn

Joined: Mar 02, 2006
Posts: 19
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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"/>


[My Blog]
All roads lead to JavaRanch
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Joined: Mar 02, 2006
Posts: 19
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Joined: Mar 02, 2006
Posts: 19
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

Joined: Dec 14, 2009
Posts: 129
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

Joined: Aug 27, 2011
Posts: 1
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to use different view resolvers in spring
 
Similar Threads
How to map DataSource in tomact
How to map DataSource in tomact
On a button click need to load a select one menu
How do I create a basic confirmation page with dynamic content?
How dispatcher-servlet.xml works