我的蛋壳

倡导自由、开放、分享的Java技术社区 http://www.javaread.com

 

Grails Feeds Plugin 使用经验小结

先采用标准使用方法:

 1class YourController {
 2    def feed = {
 3        render(feedType:"rss", feedVersion:"2.0"{
 4            title = "My test feed"
 5            link = "http://your.test.server/yourController/feed"
 6            description = "The funky Grails news feed"
 7        Article.list().each() {article -> 
 8            entry(article.title) {
 9                 link = "http://your.test.server/article/${article.id}" 
10                article.content // return the content 
11            }

12        }

13      }

14     }

15 }

        如果在一个grails应用只有一个feed实例,没发现什么问题,觉得这个插件还挺不错的。因为JavaRead要提供多个feed,后来才发现,但是一旦超过一个,那么只有一个能用。其他的直接抛出grails异常信息:

1No such property: title for class: ArticleController
2Caused by: groovy.lang.MissingPropertyException: No such property: title for class: ArticleController

 
       最后翻了一下插件的代码,改了一下迂回解决了这个问题。

 1   def feed = {
 2        def builder = new feedsplugin.FeedBuilder()
 3        builder.feed {
 4            title = "JavaRead热文"
 5            link = "http://www.javaread.com/article/list"
 6            description = "最新鲜的Java资讯"
 7            Article.listOrderById(max:20, order:"desc") .each() { article ->
 8                entry {
 9                    title = article.title
10                    link = "http://www.javaread.com/article/show/${article.id}"
11                    article.overview
12                }

13            }

14        }

15        def feed = builder.makeFeed('rss')
16        StringWriter writer = new StringWriter()
17        SyndFeedOutput output = new SyndFeedOutput()
18        output.output(feed,writer)
19        writer.close()
20        render(writer.toString())
21     }




本文作者:javaread.com

posted on 2008-07-24 16:35 javaread.com 阅读(1003) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

导航

统计

常用链接

留言簿(3)

随笔档案

Java

友情链接

搜索

最新评论

阅读排行榜

评论排行榜