java - How to return a json respone or redirect to other view depending on the condition? -
i have search criteria depending on list result . if list contains 1 data want return edit view of particular data.if list contains more 1 data want return jsonresponse show data table .
i tried did not data table nor did view
if(reservationgriddatapage.getsize() > 1){ gridjsonresponse jsonresponse = reservationgridhelper.prepareresponse(reservationgriddatapage); jsonresponse.setitotaldisplayrecords(gridmanager.gettotalsearchedreservations(pagerequest, null, entitystatecode, searchparams)); jsonresponse.setsecho(secho); return jsonresponse; }else{ long entitykey = null; list<reservationgriddata> content = reservationgriddatapage.getcontent(); (reservationgriddata t : content) { entitykey = t.getid(); } redirectview redirectview = new redirectview("/xxx/editres?id="+entitykey); return new modelandview(redirectview); }
just return view name of typestring
. then, if reservationgriddatapage.getsize() > 1
returns true, redirect method of controller anotated @responsebody
return json object.
@requestmapping(value = "//... mapping blah blah ...", method = requestmethod.post) public string method1(){ if(reservationgriddatapage.getsize() > 1){ return "redirect:/json-response.do"; }else{ long entitykey = null; list<reservationgriddata> content = reservationgriddatapage.getcontent(); (reservationgriddata t : content) { entitykey = t.getid(); } //... //some other codes return "the-name-of-my-edit-view"; } } @requestmapping(value = "/json-response.do", method = requestmethod.get) public @responsebody gridjsonresponse jsonresponsecontroller(){ //... other codes gridjsonresponse jsonresponse = reservationgridhelper.prepareresponse(reservationgriddatapage); jsonresponse.setitotaldisplayrecords(gridmanager.gettotalsearchedreservations(pagerequest, null, entitystatecode, searchparams)); jsonresponse.setsecho(secho); //... return gridjsonresponse; }
Comments
Post a Comment