From Javascript Int to a Java String -


so have variable in javascript can both string , int, need send java method. though that, since it's easier change number string instead of opposite, set variable string. i'm gonna post code

this javascript, variable valore 1 can both int , string

$(".save").click(function() {                  var valore = $("#valore").val();                                 var connettore = $("#connettore option:selected").text().split(" ").join("");                         $.get("select"+connettore+".do", {                      nomecampo: $("#colonnariferim").val().tolowercase(),                     valore: valore                  }, function (data) {                             (var = 0; < data.connettore.length; i++) {                                 var conn = data.connettore[i];                                                   }                         }                 );   

this java function

@requestmapping("selectcompensi") @responsebody @transactional public modelwrapper<list<tracciatocompensi>> selectcompensi(@requestparam string nomecampo,      @requestparam string valore){            session s = hibernatefactory.getcurrentsession();     modelwrapper<list<tracciatocompensi>> resp = new modelwrapper<list<tracciatocompensi>>();     criteria c = s.createcriteria(tracciatocompensi.class)             .add(restrictions.eq(nomecampo, valore));     list<tracciatocompensi> alist = (list<tracciatocompensi>) c.list();      query query = s.createsqlquery("insert tracciato_compensi_clone (codiceordine, codiceservizio, codiceunivococomponente, coefficientecanonemese, "+nomecampo+", compensi1, rev, mod_time, mod_user) ("                 +"select codiceordine, codiceservizio, codiceunivococomponente, coefficientecanonemese, "+nomecampo+", "+nomecampo+", rev, mod_time, mod_user tracciato_compensi "+nomecampo+" = '"+valore+"')");                      resp.put("connettore", alist);     query.executeupdate();     return resp; } 

you can ignore query, stuff works, criteria , rest. problem seems obvious, if valore numeric, function crash, tried add random character number, , tried convert using tostring() javascript if use isnumeric() function of jquery , says isn't numeric, still crashes

the method you're looking string.valueof(object):

    string valore1 = "5";     system.out.println(string.valueof(valore1));      int valore2 = 5;     system.out.println(string.valueof(valore2)); 

gives:

5 5 

in console.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -