为要分配给 bean 字段的操作配置请求参数 [英] configure request param for action to be assigned to fields of bean

查看:30
本文介绍了为要分配给 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.

示例:sortColumnsortType(asc,desc)、过滤值、pagenumitemsonpage等等

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.

问题是参数以这种方式发送 iSortColumniDisplayTotalLengthiTotalItems 等等但我需要将它们分配给 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 关联或聚合到操作类的常用方法.操作类属性可以通过具有属性访问器的名称直接使用.嵌套的 bean 属性可以通过 OGNL 访问,方法是指定适当的 OGNL 表达式,该表达式是属性的路径.假设所有属性访问器都没有对 bean 的 null 引用.这可以通过为属性提供相应的 getter 和 setter 并在必要时初始化 bean 引用来实现.因此,bean.iSortColumnbean.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 Basics.
  • 基础 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 字段的操作配置请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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