Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem: no data charge #58

Open
ghost opened this issue Mar 8, 2017 · 1 comment
Open

problem: no data charge #58

ghost opened this issue Mar 8, 2017 · 1 comment

Comments

@ghost
Copy link

ghost commented Mar 8, 2017

I trying to make an autocomplete with bootstrap typeahead using the framework spring, but it not working. the idea is that when typing a code it show all datas from the database and when I select one, this complete me the code and the name.

This is my HTML code
@

<div class="form-group">
<div class="col-sm-11">
<label for="cuenta_codigo" class="col-sm-2 control-label">Cuenta Contable:</label>
<div class="col-sm-3">
   <form:input id="cuenta_codigo" path="cuenta.ccuenta_cod" cssClass="form-control" placeholder="Código" autocomplete="off" data-provide="typeahead"/>
</div>
<div class="col-sm-6">
   <form:input id="cuenta_nombre" path="cuenta.vcuenta_nombre" cssClass="form-control" placeholder="Nombre" />
</div>
</div>

This is my Controller

@

@RequestMapping(value = "/master/cuenta/ajax", produces = MediaType.APPLICATION_JSON_VALUE)
public List<AutoType> getAjax(@RequestParam("type") String type, @RequestParam("param") String param){

List<AutoType> lista = new ArrayList<>();

try {
lista = cuentaService.getCuentaAjaxByCode(param);
} catch (Exception e) {
logger.error(e);
}

return lista;
}

This is my JavaScript code

@

<script>
$(document).ready(function () {
$('#cuenta_codigo').typeahead({
source: function (request, response) {
    $.ajax({
        url: "/master/cuenta/ajax",
        type: "POST",
        data: {
            param: request.param
        },
        dataType: "json",
        success: function (data) {
            response(data);
        }
    });
}
});
});
</script>}

If it necessary these are my Dao implement and Service Implement

Dao Implement

@

@Override
public List<Cuenta> getCuentaAjax(String code) {
String namedQuery = "Cuenta.getAjaxByCode";
List<FilterHQL> filters = new ArrayList<>();
filters.add(new FilterHQL("ccuenta_cod", code+"%"));
return hibernateUtil.fetchListByParamHQL(filters, Cuenta.class, namedQuery);
}

Service Implement

@

@Override
public List<AutoType> getCuentaAjaxByCode(String code) {
List<AutoType> json = new ArrayList<>();
List<Cuenta> lista = cuentaDao.getCuentaAjax(code);
for (Cuenta cuenta : lista) {
    json.add(new AutoType(cuenta.getCcuenta_cod(), cuenta.getVcuenta_nombre()));
}
return json;
} 
@yokidokii
Copy link

Why not use the 'ajax' option instead of passing a function on the 'source' ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant