java - Check For Modal Attribute Existence In Controller Method before adding -


i have spring controller want method handle request , redirect 1 keeping value attached, use redirectattributes on first 1 , @modalattribute on second, thing not have modal attribute existing want add if exists.

@requestmapping("/main") public string getmain(model model,httpsession session,@modalattribute list<loans> loanslist){     if(session.getattribute("user") != null){         if(session.getattribute("current_start")!=null){             model.addattribute("loans",loandao.findall((integer) session.getattribute("current_start")));         } else {             model.addattribute("loans",loandao.findall(0));             session.setattribute("current_start",0);         }         model.addattribute("loan",new loan());         model.addattribute("countries",countrydao.findall());         model.addattribute("types",typedao.findall());         session.setattribute("total_loans_number", loandao.findcount());         return "main";     } else {         return "redirect:index";     } } 

and redirecting 1 one

@requestmapping(value = "/search") public string searchloans(model model,redirectattributes redirectattributes,                           @requestparam string keyword){     redirectattributes.addattribute("loanslist",loandao.findall(keyword));     return "redirect:/main"; } 

but here @modalattribute fails because not exist,sometimes request main out loanslist, how make condition add if exists ? or how correctly ?

you can let spring populate model attributes using @modalattribute annotation on methods:

@modalattribute("results") public list<loans> populateloans() {     return new arraylist<loans>(); }  @requestmapping("/main") public string getmain(model model,httpsession session,@modalattribute("results") list<loans> loanslist){     if (collectionutils.isnotempty(loanlist)) {         // if loan list not empty.      } } 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -