How can I cache data inside a composite component?

爱⌒轻易说出口 提交于 2019-12-13 16:23:30

问题


I've been working with this dynamic list component:

How to implement a dynamic list with a JSF 2.0 Composite Component?

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.

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

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

回答1:


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

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.

See also:

  • How to save state when extending UIComponentBase


来源:https://stackoverflow.com/questions/29032046/how-can-i-cache-data-inside-a-composite-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!