configure request param for action to be assigned to fields of bean(配置请求参数以将操作分配给 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.
这篇关于配置请求参数以将操作分配给 bean 的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:配置请求参数以将操作分配给 bean 的字段
基础教程推荐
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 降序排序:Java Map 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01