سؤال

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.

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.

So i did implement a DatatableParamBean which contain all params needed to work properly.

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.

Consider that DatatableParamBean has reference in my action class as 'bean';

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

هل كانت مفيدة؟

المحلول

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; }

References:

  • 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.
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top