Rory's Blog
Happy study,Happy work,Happy life
posts - 22,  comments - 46,  trackbacks - 0
只是自己的想法,不对不要扔鸡蛋哦。

今天突发奇想的实现一个小小的cache。把分类categories放入map中,cache起来。
    private void cache() {
        
if(log.isDebugEnabled()){
            log.debug(
"Starting cache the categories");
        }
        cacheCategoryMap 
= new HashMap();
        cacheCategoryMap.put(
"categories",categoryDao.getCategories());
    }

然后我想在interceptor里面把categories写到ognlvaluestack里面这样我在ftl里面就可以<#list categories>....</#list>了。因为这个是在每个页面的header.ftl里面的。我也就不需要再每个action里面去get一下了。
刚开始我implements Interceptor

        final OgnlValueStack stack = ActionContext.getContext().getValueStack();
        stack.setValue(
"categories" ,categoryManager.getCategories());
        
return invocation.invoke();
可是这样也不可以。后来我想到是不是action执行完毕之后就把stack中的这个值清空了我又用了。AroundInterceptor 我想在after里面去设置不就可以了。
    protected void after(ActionInvocation dispatcher, String result) throws Exception {
        
final OgnlValueStack stack = ActionContext.getContext().getValueStack();
        stack.setValue(
"categories" ,categoryManager.getCategories());
    }
可是这样还是不可以。我晕了。我想是不是要在action里面声明一下categories。
    private List categories;

    
public List getCategories() {
        
return categories;
    }


    
public void setCategories(List categories) {
        
this.categories = categories;
    }

然后在before里面去get就可以了。
    protected void before(ActionInvocation invocation) throws Exception {
        
final OgnlValueStack stack = ActionContext.getContext().getValueStack();
        stack.setValue(
"categories" ,categoryManager.getCategories());
    }

总算实现了。不过还要在每个action里面声明一下categories,这样还是很不好的。刚才有人建议用filter。我在试试吧.


http://leaf.jdk.cn/index.php/archives/91
posted on 2006-03-21 11:37 莫多 阅读(1109) 评论(0)  编辑  收藏 所属分类: Webwork

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


网站导航:
 

<2006年3月>
2627281234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(1)

随笔分类(27)

随笔档案(22)

Friends

搜索

  •  

积分与排名

  • 积分 - 61429
  • 排名 - 847

最新评论

阅读排行榜

评论排行榜