2

Do you know why I am getting this error?

SEVERE: Servlet.service() for servlet [enemr] in context with path [/enemr] threw exception [Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.github.dandelion.datatables.core.ajax.DatatablesCriterias]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.github.dandelion.datatables.core.ajax.DatatablesCriterias.<init>()] with root cause
java.lang.NoSuchMethodException: com.github.dandelion.datatables.core.ajax.DatatablesCriterias.<init>()

I changed my controller from this

@RequestMapping(value = "/results", method = RequestMethod.GET)
    public @ResponseBody DatatablesResponse<Results> findAllForDataTables(HttpServletRequest request) {

        DatatablesCriterias dataTableCriterias = DatatablesCriterias.getFromRequest(request);
        DataSet<Results> results = this.resultsServiceimpl.findResultsWithDatatablesCriterias(dataTableCriterias);
        return DatatablesResponse.build(results, dataTableCriterias);
    }

to this:

@RequestMapping(value = "/results", method = RequestMethod.GET)
    public @ResponseBody 
    DatatablesResponse<Results> findAllForDataTables(@DatatablesParams DatatablesCriterias criterias) {

        DataSet<Results> results = this.resultsServiceimpl.findResultsWithDatatablesCriterias(criterias);
        return DatatablesResponse.build(results, criterias);
    }

and suddenly stop working

any help highly appreciated.

I am using spring 3.2 and dandelion datatables 1.1.0

QGA
  • 3,114
  • 7
  • 39
  • 62
  • The exception is as clear as it can be: there's no default constructor for the DatatablesCriterias class, and the bean factory requires one. You shouldn't be passing that as a parameter. – duffymo Oct 02 '15 at 09:18
  • I just followed this sample [here](https://github.com/dandelion/dandelion-datatables-samples/blob/master/datatables-jsp-ajax/src/main/java/com/github/dandelion/datatables/web/ajax/AjaxController.java) – QGA Oct 02 '15 at 09:22
  • 1
    Believe the JVM, not the sample. Who creates criteria? – duffymo Oct 02 '15 at 09:23
  • It is a project created by dandelion. It is based on JQuery Datatables. See their websites [here](http://dandelion.github.io/components/datatables/) – QGA Oct 02 '15 at 09:34
  • I think the first controller is correct; the JVM agrees with me. Why the change? – duffymo Oct 02 '15 at 11:56
  • Looking at the [documentation](http://dandelion.github.io/components/datatables/1.1.0/docs/html/#starting-from-spring-3-1) I can use the spring extra module to do the above – QGA Oct 02 '15 at 12:14

1 Answers1

1

When you changed your controller to use DatatablesParams annotation you need to enable a resolver which will instantiate DatatablesCriterias object. Because spring 3.2 is in use, DatatablesCriteriasMethodArgumentResolver need to be enabled:

through xml:

     <!-- Add support for @DatatablesParams annotations in controller's methods -->
   <mvc:annotation-driven>
      <mvc:argument-resolvers>
         <bean class="com.github.dandelion.datatables.extras.spring3.ajax.DatatablesCriteriasMethodArgumentResolver" />
      </mvc:argument-resolvers>
   </mvc:annotation-driven>

or java config:

   @Configuration
   @EnableWebMvc
   public class MyWebConfig extends WebMvcConfigurerAdapter {
      @Override
      public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
         argumentResolvers.add(new DatatablesCriteriasMethodArgumentResolver());
      }
   }
ajurasz
  • 716
  • 1
  • 8
  • 9