Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
49
rated 0 times [  53] [ 4]  / answers: 1 / hits: 14368  / 11 Years ago, mon, february 24, 2014, 12:00:00

Here is my relevant codes.my out put is like this.
enter



I need to send region and tsrId as parameters to query.
here is my code



jsp



Here is my ajax request with jquery



<script type=text/javascript>
$(document).ready(function() {
var region = document.getElementById('region').value;
var tsrId = document.getElementById('tsrId').value;
$('#tsrId').autocomplete({
serviceUrl: 'getTsrId.html',
data: ({queryData : {region:region,tsrId:tsrId}}),
//delimiter: ,,
transformResult: function(response) {
return {suggestions: $.map($.parseJSON(response), function(item) {return { value: item.name, data: item.id };
})};}});});
</script>


here is the HTML form



  <td>Region</td>
<td><input type=text name=region id=region><div class=autocomplete-suggestions></div></td>
<td>TSR ID</td>
<td><input type=text name=tsrId id=tsrId maxlength=8><div class=autocomplete-suggestions2></div></td>


here is my controller



@RequestMapping(value = /getTsrId, method = RequestMethod.GET)
public @ResponseBody List<TSRMaster> getTsrId(@RequestParam String tagName,@RequestBody QueryData queryData) {
List<TSRMaster> tsrMasterList=new ArrayList<TSRMaster>();
tsrMasterList=gpsdao.getTsrIdList(queryData.getRegion(),queryData.getTsrId());
return tsrMasterList;
}


here is my bean class for requestMapping



public class QueryData {

private String region;
private String tsrId;

public String getRegion() {
return region;
}
public void setRegion(String region) {
this.region = region;
}
public String getTsrId() {
return tsrId;
}
public void setTsrId(String tsrId) {
this.tsrId = tsrId;
}

}


Please help me to sort out this issue..is there any other alternative solution, please mention that path below
thanks.


More From » jquery

 Answers
2

The only way I have been able to make this work so far is to call JSON.stringify() on the client, which turns a JavaScript Object into a JSON String. (To be cross browser compatible you would need json2.js)



Then you send this as a String parameter to Spring and parse it there using the Jackson library.



Sample Code:



Java Script



data: ({queryData : JSON.stringify({region:region,tsrId:tsrId}})),


Java



RequestMapping(value = /getTsrId, method = RequestMethod.GET)
public @ResponseBody List<TSRMaster> getTsrId(@RequestParam String tagName,@RequestParam String queryData) {

ObjectMapper myMapper = new ObjectMapper();
QueryData myQueryData = myMapper.readValue(queryData, QueryData.class);

List<TSRMaster> tsrMasterList=new ArrayList<TSRMaster>();
tsrMasterList=gpsdao.getTsrIdList(myQueryData.getRegion(),queryData.getTsrId());
return tsrMasterList;
}

[#47473] Saturday, February 22, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
shylaelisan

Total Points: 37
Total Questions: 94
Total Answers: 110

Location: Angola
Member since Tue, May 5, 2020
4 Years ago
;