配置请求参数以将操作分配给 bean 的字段
我正在使用 www.datatables.net
.JS 框架在表格中显示数据.它具有服务器模式,并在此模式下发送大量参数.
I am using www.datatables.net
. JS framework to show data in tables. It has server mode and it sends a lot of params during this mode.
示例:sortColumn
、sortType(asc,desc)
、过滤值、pagenum
、itemsonpage
等开.
Example: sortColumn
, sortType(asc,desc)
, filter values, pagenum
, itemsonpage
and so on.
所以我在行动中处理它.我分配给每个请求参数字段,它工作正常.
So i handle it in action. i assign to each request param field in action and it work fine.
但现在我有几张桌子.所以我必须采取不同的行动,但要求参数相同,而且有很多.将粘贴代码从一个操作复制到另一个操作不是一个好主意.
But now i have several table. So i have to make different actions but request params same and there are a lots of them. It is not a good idea to copy paste code from one action to another.
所以我确实实现了一个 DatatableParamBean
,其中包含正常工作所需的所有参数.
So i did implement a DatatableParamBean
which contain all params needed to work properly.
问题是params这样发送iSortColumn
、iDisplayTotalLength
、iTotalItems
等但我需要将它们分配给 bean 字段.
problem is that params send this way iSortColumn
, iDisplayTotalLength
, iTotalItems
and so on
but i need to them to be assigned to bean fields.
bean.iSortColumn, bean.iDisplayTotalLength and so on.
考虑到 DatatableParamBean
在我的操作类中引用为bean";
Consider that DatatableParamBean
has reference in my action class as 'bean';
是否有办法覆盖分配请求参数值的默认机制?我现在找到的唯一解决方案是使用所有这些参数创建一个动作说 DatatableAction
类,并在我需要处理 dataatble 时创建一个新动作,使用从 DatatableAction
If there is a way to override default mechanism of assigning request param values?
Only solution i found for now is to create an action say DatatableAction
class with all this params and create an new action if i need to handle dataatble, using extending from DatatableAction
推荐答案
这是将 bean 关联或聚合到操作类的常用方法.动作类属性可以通过具有属性访问器的名称直接使用.可以通过 OGNL 访问嵌套的 beans 属性,方法是指定适当的 OGNL 表达式,该表达式是属性的 path.假设所有属性访问器都没有对 bean 的 null
引用.这可以通过为属性提供相应的 getter 和 setter 并在必要时初始化 bean 引用来实现.因此,bean.iSortColumn
、bean.iDisplayTotalLength
是设置/获取 bean
属性的有效 OGNL 表达式.但是您需要在操作中对其进行初始化.像这样
This is usual way to associate or aggregate a bean to the action class. The action class properties can be used directly by name that have property accessors. Nested beans properties are accessible via OGNL by specifying proper OGNL expression which is a path to the property. Assumed all properties accessors have not null
references to beans. That could be achieved via providing corresponding getters and setters to properties and initializing bean references if necessary. So, bean.iSortColumn
, bean.iDisplayTotalLength
are valid OGNL expressions to set/get the bean
properties. But you need to initialize it in the action. Like this
private Bean bean = new Bean();
public Bean getBean() { return bean; }
参考资料:
- 要熟悉 OGNL 的工作原理,您可以阅读 OGNL 基础知识.
- 基本 OGNL 参考资料,包括指向 OGNL 语言指南的链接.李>
- To be familiar how OGNL works you can read in the OGNL Basics.
- The base OGNL reference including a link to the OGNL language guide.
相关文章