Sealyu

--- 博客已迁移至: http://www.sealyu.com/blog

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  618 随笔 :: 87 文章 :: 225 评论 :: 0 Trackbacks
项目中客户提了一个要求,在进行完操作离开表格页面后,如果再回到这个页面,要求能保存以前离开时的样子,(排序,过滤和条目属性等等。)
刚开始自己研究了一下代码,新建一个form来储存TableFacade的limit属性到session里,实现了这个功能。
后来发想Jmesa本身就有一个stateAttr属性用来保存状态,wiki中有详细的使用说明:
State  

The State interface is used to set and retrieve the table Limit. Implementations will set the Limit so that it can be retrieved at a later time. This is useful so a user can return to a specific table with it filtered, sorted, and paged exactly like they left it.

All you have to do is set the stateAttr to the parameter to look for in the url, or the attribute in the request, to tip the table off that the Limit in the users session should be used.

Example

For example in the TableFacade just pass in the name of the parameter to use:

TableFacade tableFacade =TableFacadeFactory.createTableFacade(id, request);
tableFacade.setStateAttr("restore");

The same goes for using the tags:

<jmesa:tableFacade
        id="basic"
        stateAttr="restore"
        ...
        >

As you can see in the following example, by passing in a parameter of "restore=true" then the table is rendered in the same way that you left it. That is really all there is too it!

Note: Just be sure that you have a unique table id for each table that you define. Technically the Limit object for each table is stored in the users session keyed by the table id. If the tables are not unique then you will overwrite one Limit with another.



posted on 2009-01-21 10:51 seal 阅读(583) 评论(0)  编辑  收藏 所属分类: web

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


网站导航: