0

I am succesfully populating first dropdown with spring mcv but populating the second one I think there is some inconsistency between sprig and jquery, missing something.

While populating the second dropdown based on the first dropdown's change jquery function I am getting the error:

java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList

Note: The TaskDetail class has all getter and setters.

Any help would be appreciated, thanks.

Edit: Nothing wrong with the code, but I forgot to add jackson to the project.

Here is my code:

DAO Classes:

@SuppressWarnings("unchecked")
@Override
public HashMap<Integer, String> findAllTasksForDropdown() {
    HashMap<Integer, String> tasks = new HashMap<Integer, String>();

    Criteria criteria = createEntityCriteria()
            .addOrder(Order.asc("taskId"));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);//To avoid duplicates.
    List<Task> list = criteria.list();
    Iterator<Task> itr = list.iterator();
    while(itr.hasNext())
    {
        Task task = itr.next();
        tasks.put(task.getTaskId(), task.getTaskName());
    } 

    return tasks;
}

@SuppressWarnings("unchecked")
@Override
public List<TaskDetail> findAllTaskDetailForDropdown(Integer taskId) {
    Criteria criteria = createEntityCriteria()
            .add(Restrictions.eqOrIsNull("taskId", taskId))
            .addOrder(Order.asc("taskDetailId"));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);//To avoid duplicates.
    List<TaskDetail> taskDetails = criteria.list();

    return taskDetails;
}

Controller:

@RequestMapping(value="/taskDetailListDD/{taskId}", method = RequestMethod.GET)
public @ResponseBody List<TaskDetail> initTaskDetailList(@PathVariable("taskId") int taskId){
    List<TaskDetail> taskDetailList = taskDetailService.findAllTaskDetailForDropdown(taskId);
    return taskDetailList;
}

@RequestMapping(value="/taskListDD", method = RequestMethod.GET)
public void initTaskList(ModelMap model){
    HashMap<Integer, String> taskList = taskService.findAllTasksForDropdown();
    model.addAttribute("taskListDD", taskList);
}

JSP:

<div class="well lead">Task Info Registration Form</div>
    <form:form method="POST" modelAttribute="taskInfo" class="form-horizontal">

        <div class="row">
            <div class="form-group col-md-12">
                <label class="col-md-3 control-lable" for="taskId">Task Id</label>
                <div class="col-md-7">

                    <form:select id="selectTaskListDD" path='taskListDD'> 
                        <option value="">-Select-</option> 
                        <form:options items="${taskListDD}"/>
                    </form:select>

                    <div class="has-error">
                        <form:errors path="taskId" class="help-inline"/>
                    </div>
                </div>
            </div>
        </div>

        <script>
            $("#selectTaskListDD").change(function(){
                var taskId = $("#selectTaskListDD").val();
                $.ajax({ //ERROR IS THROWN HERE
                    type: 'GET',
                    url: "/taskDetailListDD/" + taskId,
                    success: function(data){
                        var slctTaskDetailDD=$('#selectTaskDetailDD'), option="";
                        slctTaskDetailDD.empty();

                        for(var i=0; i<data.length; i++){
                            option = option + "<option value='"+data[i].taskDetailId + "'>"+data[i].taskDetailName + "</option>";
                        }
                        slctTaskDetailDD.append(option);
                    },
                    error:function(){
                        alert("error");
                    }

                });
            });
        </script>

        <div class="row">
            <div class="form-group col-md-12">
                <label class="col-md-3 control-lable" for="taskDetailId">Task Detail Id</label>
                <div class="col-md-7">

                    <form:select class="form-control" id="selectTaskDetailDD" path="taskDetailListDD">
                       <option value="-" label="-Select-"/>
                    </form:select>

                    <div class="has-error">
                        <form:errors path="taskDetailId" class="help-inline"/>
                    </div>
                </div>
            </div>
        </div></form:form>
  • Possible duplicate of [Spring MVC - How to return simple String as JSON in Rest Controller](https://stackoverflow.com/questions/30895286/spring-mvc-how-to-return-simple-string-as-json-in-rest-controller) – Taplar Nov 16 '17 at 20:00
  • I checked the question that you said possible duplicate, but I did not understand. Can you explain on the code that I provided, please. – Oğuzhan Onur Nov 17 '17 at 20:34
  • That other post discusses how to make a Spring Controller return json. That's what you are after. – Taplar Nov 17 '17 at 20:37
  • Thank you @Taplar, it seems I forgat to add jackson to my project. – Oğuzhan Onur Nov 17 '17 at 21:02

0 Answers0