0

In my Controller I have

@RequestMapping(value="/getCounties", method = {RequestMethod.GET},produces=MediaType.Application_JSON_VALUE)
public @Responcebody List<Counties>(@RequestParam String province){

    List<Counties> county = this.xService.getCounties(county);
    return county;
}

This method send the province chosen in the form down to the repository and join on the counties within that province.

In my dropdown on the form how do I return these values into the dropdown.

I currently have

<tr>
    <td>
        <form:select path="cdGcd" class="textbox" onclick="getCounty()">  
            <form:option value="-" label="Please Select"/>
            <form:options path="county" items='${county}' itemValue = "countycode" itemLabel="countydescription"/>
        </form:select>
    </td>
</tr>

1 Answer 1

1

You can not return List directly form controller. For passing data from controller to JSP you need to add data in Model and return respective JSP page.

So you need to change your method to,

@RequestMapping(value="/getCounties", method = {RequestMethod.GET})
public String getCountries(@RequestParam String province, Model model){
    List<Counties> county = this.xService.getCounties(county);
    model.addAttribute("county",county);
    return "jsp page";
}

If you want to achieve this using AJAX then,you need to return JsonObject from controller.

Sign up to request clarification or add additional context in comments.

3 Comments

I am passing the JsonObject through, but how do I call it from the AJAX function up to the dropdown?
I am passing the JsonObject through, but how do I call it from the AJAX function up to the dropdown?
@user3399863 you need to make ajax call to controller and return JsonObject and get respective JsonObject in ajax response and append response data with select. For more help update your question with whatever you are tried upto so i can give proper implementation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.