如何在复合组件中缓存数据? [英] How can I cache data inside a composite component?

查看:76
本文介绍了如何在复合组件中缓存数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用此动态列表组件:

I've been working with this dynamic list component:

如何实施具有JSF 2.0复合组件的动态列表?

我想做的一件事情是缓存列表"的原始值,这样,当用户从列表中添加或删除某项内容时...我知道添加/删除了哪些内容,这样我就可以与他们做一些不同的事情.例如,已删除"项目将仅具有删除线.或者,添加的"项目将具有不同的背景,以表明它是最近添加的.

One of the things I'd like to do is cache the original value of "list" so that, when a user adds or removes something from this list...I know which ones were added/removed so that I can do something different with them. For example, a "removed" item would simply have a strikethrough instead. Or, an "added" item would have a different background to show that it was recently added.

我现在似乎可以正常工作的唯一方法是使组件本身包含3个不同的列表

The only way I seem to have this working right now is for the component itself to take in 3 different lists

<mycomp:dynamicList list="#{bean.list}" addList="#{bean.addList}" 
    deleteList="#{bean.deleteList}"/>

这似乎太麻烦了.只有网页/组件才需要了解这三个列表中的区别...一旦实际提交了表单,则支持Bean仅需要知道列表"的新值.因此,理想情况下,我只想使用:

This seems overly burdensome. Only the web page/component needs to know about the differences in these three lists...once the form is actually submitted, the backing bean only needs to know the new value of "list". So, ideally, I'd just like to use:

<mycomp:dynamicList list="#{bean.list}"/>

推荐答案

继承的

Make use of the JSF view state as available by inherited getStateHelper() method. This basically acts like the JSF view scope.

请确保您不在JSF视图状态下存储/复制/复制整个模型(列表),而仅存储已添加/已删除项目的索引.

Make sure that you don't store/copy/duplicate whole model (the list) in the JSF view state, but only the indexes of added/removed items.

这篇关于如何在复合组件中缓存数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆