Can't map a Query String parameters to my JavaBean (using Spring 4 and Datatables) -


i'm stuck trying map querystring parameters spring javabean command object here, , couldn't find answer question far.

i'm using jquery datatables plugin server side processing each action in datatable, triggers ajax request spring application.

this parameters datatable plugin sending rest service:

http://localhost:8080/relatorios/produtos-source?draw=2&columns[0][data]=nome&columns[0][name]=&columns[0][searchable]=true&columns[0][orderable]=true&columns[0][search][value]=&columns[0][search][regex]=false&columns[1][data]=nomesalternativos&columns[1][name]=&columns[1][searchable]=true&columns[1][orderable]=true&columns[1][search][value]=&columns[1][search][regex]=false&order[0][column]=2&order[0][dir]=asc&start=0&length=10&search[value]=ss&search[regex]=false&_=1400248561282 

this how receiving in spring controller:

@requestmapping(value = "/produtos-source", method = requestmethod.get) @responsestatus(httpstatus.ok) @responsebody public produtotable datatablerequest(@modelattribute datatablecriterias criterias) {     ... } 

and finally, datatablecriterias javabean (indicated @modelattribute):

public class datatablecriterias {     private int draw;     private int start;     private int length;      private map<searchcriterias, string> search;      private list<map<ordercriterias, string>> order;      private list<column> columns;      public enum searchcriterias {         value,         regex     }      public enum ordercriterias {         column,         dir     }      public class column {         private string data;         private string name;         private boolean searchable;         private boolean orderable;         private map<searchcriterias, string> search;     } } 

(get / setters ommited)

this works perfectly! if remove line:

private list<column> columns; 

then spring automagically populates datatablecriterias bean query string (but of course, don't columns property mapped)

but line added, error:

2014-05-16 17:20:16.605 error 2368 --- [tomcat-http--99] o.a.c.c.c.[.[.[.[dispatcherservlet]      : servlet.service() servlet [dispatcherservlet] in context path [/relatorios] threw exception [request processing failed; nested exception org.springframework.beans.invalidpropertyexception: invalid property 'columns[0][data]' of bean class [com.bergermobile.rest.domain.datatablecriterias]: illegal attempt property 'columns' threw exception; nested exception org.springframework.beans.nullvalueinnestedpathexception: invalid property 'columns' of bean class [com.bergermobile.rest.domain.datatablecriterias]: not instantiate property type [com.bergermobile.rest.domain.datatablecriterias$column] auto-grow nested property path: java.lang.instantiationexception: com.bergermobile.rest.domain.datatablecriterias$column] root cause  org.springframework.beans.nullvalueinnestedpathexception: invalid property 'columns' of bean class [com.bergermobile.rest.domain.datatablecriterias]: not instantiate property type [com.bergermobile.rest.domain.datatablecriterias$column] auto-grow nested property path: java.lang.instantiationexception: com.bergermobile.rest.domain.datatablecriterias$column     @ org.springframework.beans.beanwrapperimpl.newvalue(beanwrapperimpl.java:651) 

as see it, main problem 'column' parameter sent datatable plugin bidimensional , tridimensional array:

columns[0][data]=nome columns[0][search][regex]=false 

so, looks bean correct, error , i'm stuck.

any ideas?

thanks lot!

ok, ended fixing issue modifying parameters sent server, transform 2 3d array of columns 2d array. so:

columns[0][search][value]=myvalue columns[0][search][regex]=false 

ended being:

columns[0][searchvalue]=myvalue columns[0][searchregex]=false 

this how in databables:

$('#produtostable').datatable({     serverside: true,     ajax: {         "url": "produtos-source",         "data": function(data) {             planify(data);           }      } });  function planify(data) {     (var = 0; < data.columns.length; i++) {         column = data.columns[i];         column.searchregex = column.search.regex;         column.searchvalue = column.search.value;         delete(column.search);     } } 

this way can receive properties in model object using field:

private list<map<columncriterias, string>> columns; 

just reference, here controller:

@requestmapping(value = "/produtos-source", method = requestmethod.get) @responsestatus(httpstatus.ok) @responsebody public produtotable datatablerequest(@modelattribute datatablecriterias criterias) {     produtotable produtotable = produtosservice.findprodutos();     produtotable.setdraw(criterias.getdraw());     return produtotable; } 

and here final datatablecriterias @modelattriute:

public class datatablecriterias {     private int draw;     private int start;     private int length;      private map<searchcriterias, string> search;      private list<map<columncriterias, string>> columns;      private list<map<ordercriterias, string>> order;      public enum searchcriterias {         value,         regex     }     public enum ordercriterias {         column,         dir     }     public enum columncriterias {         data,         name,         searchable,         orderable,         searchvalue,         searchregex     } 

(get/setters omitted)


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -