0

I;m trying to create RSS feeds for my web site. I follow the tutorial from mkyong (http://www.mkyong.com/spring-mvc/spring-3-mvc-and-rss-feed-example/) which was quite useful. According to this tutorial i create a model class and the following class

public class CustomRssViewer extends AbstractRssFeedView{


    @Override
protected void buildFeedMetadata(){
        //some code
    }

    @Override
protected List<Item> buildFeedItems(){
        //some code
    }


}

And finally the controller class

    @Controller
    public class RssController {

   @RequestMapping(value="/rssfeed", method = RequestMethod.GET)
   public ModelAndView getFeedInRss() {

             //set the RSS content
          ModelAndView mav = new ModelAndView();
          mav.setViewName("rssViewer");
          mav.addObject("feedContent", items);

          return mav;

       }

 }

According to the tutorial the View rssViewer belongs the class CustomRssViewer , so i need to write it at the dispatcher servlet the following lines of code:

   <bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />

<bean id="rssViewer" class="com.mkyong.common.rss.CustomRssViewer" />

My problem is that i'm using apache tiles. So the rssViewer can not be recognised as i didn't enhanced it to the tiles definition. And i really don't know how can i do this. For example i need to write something as the following:

   <definition name="rssViewer" template="?">
     <put-attribute name="title" value=""/>
     <put-attribute name="content" value=""/>
  </definition>

At the template i don't know what to declare as well as at the put-attribute.Because until now at the template i use to declare the direction that a specific jsp exists. Something like this:

   template="/WEB-INF/pages/mypage.jsp"

And also at the view-properties i don't know what should i declare.

Thanks in advance for any comment or response.

Nick Robertson
  • 1,047
  • 4
  • 18
  • 41

1 Answers1

0

You should use a ContentNegotiatingViewResolver in conjuction with that example's BeanNameViewResolver. Just declare the order property of your already existing BeanNameViewResolver to be 1, and set the order property of the new ContentNegotiatingViewResolver to 0.

You should then configure the ContentNegotiatingViewResolver to use the appropriate View for RSS, and set the media type for RSS.

Here is an example from the Spring Docs:

 <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
  <property name="mediaTypes">
    <map>
      <entry key="atom" value="application/atom+xml"/>
      <entry key="html" value="text/html"/>
      <entry key="json" value="application/json"/>
    </map>
  </property>
  <property name="viewResolvers">
    <list>
      <bean class="org.springframework.web.servlet.view.BeanNameViewResolver"/>
      <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <property name="suffix" value=".jsp"/>
      </bean>
    </list>
  </property>
  <property name="defaultViews">
    <list>
      <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
    </list>
  </property>
</bean>

Note, they are using atom, not RSS, but the idea is the same. Also they do not set the order (which you should do).