Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I want to do a concatenated combobox, for that I am using ajax and javascript in the view, the problem is that the controller receives the data and capture me the result but when returned kicks me error can not return Map, I'm using spring mvc.

I already have 2 libraries of json, that's not the problem I think ..

JSP

....

       jQuery(document).ready(function() { 

        var contexPath = "<%=request.getContextPath()%>";
        $('#anios').change(
            function(e){
                if(jQuery(this).val() != "-1"){
                    $('#eventos').find('option').remove().end().append(
                        '<option value="-1">--Select state--</option>');
                    e.preventDefault();
                    var val = $(this).val();
                    jQuery("#eventos").removeAttr("disabled");

                    alert(val);
                    //$('#othstate').val('').hide(); 
                    $.ajax({
                        type : "POST",
                        url : contexPath + '/eventosPublicados.html',
                        dataType : 'json',
                        data : {
                            idAnio : val
                        }, success : function(data){
                            //alert(data.lstEventos);
                            //showEventos(data.lstEventos);
                            // $('#states').html( data.lstStates ); 
                        }, error : function(e) {
                            alert('Error: '+ e);
                        }
                     });
                } else {
                    $("#eventos").attr("disabled", "disabled");
                    $('#eventos').find('option').remove().end().append(
                    '<option value="-1">--- Seleccione ---</option>');
                }
            });

            function showEventos(data) {
                for (var i = 0, len = data.length; i < len; ++i) {
                    var msajax = data[i];
                    $('#eventos').append(
                    "<option value=\"" +msajax.idEvento + "\">" + msajax.nombre + "</option>");
                }
            }

        });
    </script>

..

Controller

 @RequestMapping(value= "/eventosPublicados", headers = "Accept=application/json,application/xml")
public @ResponseBody Map<String, ? extends Object> listaEventosPublicados(@RequestParam(value="idAnio", required=true) String anio) throws Exception{
    Map<String,Object> model = new HashMap<String, Object>();

    List<Evento> eventos = this.eventoService.obtenerEventosPublicadosxAnio(Integer.parseInt(anio));
    System.out.println("evento size: " + eventos.size());

    model.put("lstEventos", eventos);

    return model;
}

If I retrieve the data from the list, which means that if the value "anio" arrives, the problem is to return.

Help me pls

share|improve this question

Are you trying like this? where do you parse "eventos" to json?

 @RequestMapping(value= "/eventosPublicados", headers = "Accept=application/json,application/xml")
 @ResponseBody
 public String listaEventosPublicados (@RequestParam(value="idAnio", required=true) String anio)){
      // ..... Parsing "eventos" to json 
 }

To parse json https://code.google.com/p/google-gson/ will be useful

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.