java - Struts2 : map which contain String and double values return null for double values -
i want know how can pass hashmap
contain string , double values action javascript code ?
when edit fields double values, have null on fields, how can resolve ?
action :
public string query() { service = new serviceimpl(); v = new vehicule(); v= service.getbyimmat(im); map.put("kilo", v.getkilo()); //double value /*simpledateformat formatter5=new simpledateformat("yyyy-mm-dd"); string formats1 = formatter5.format(ss1);*/ map.put("datepicker", formats1); map.put("etat", v.getetat());//string value map.put("capacite_bagages", v.getcapacite_bagage()); //double value return "success"; }
ajax :
$.ajax({ type: 'post', url : "<s:url action='query'/>", datatype : 'json', data: { imm : selectedvalue}, success: function(result) { $.each(result, function(key,value){ $("#"+key).val(value); }); });
edit :
i want update values (string,date , double)
,for reason pass parameters map<string,object>
action jsp page.
public string query() { service = new serviceimpl(); v = new vehicule(); v= service.getbyimmat(im); map.put("kilo", v.getkilo()); //double value simpledateformat formatter5=new simpledateformat("yyyy-mm-dd"); string formats1 = formatter5.format(v.getdate()); map.put("datepicker", formats1); map.put("etat", v.getetat());//string value map.put("capacite_bagages", v.getcapacite_bagage()); //double value return "success"; }
i show in jsp,i edit in jsp page,but when want save result, double value take nan !! :
public string modifiervehicule () { service = new serviceimpl(); v= new vehicule(); v = vehiculeservice.getvehiculebyimmat(immatricul); v.setkilo((double)getkilo()); v.setdate((date)getdate()); v.setetat(getetat()); v.setcapacite_bagage((double)getcapacite_bagages()); v = service.update(v); return "success"; }
kilo field (double) has null value after editing, if edit integer value not have null value,
i think because public double getkilo()
should return double not object pass in map !!)
edit 2 :
jsp :
<script type="text/javascript"> $(document).ready(function() { $('#imm').change(function() { var selectedvalue = $('#imm').val(); if ($.trim(selectedvalue).length > 0) { $.ajax( { type: 'post', url : "<s:url action='query'/>", datatype : 'json', data: { imm : selectedvalue}, success: function(result){ $.each(result, function(key,value) { $("#"+key).val(value); } ); }); </script> <s:form cssstyle="border:0;" validate="true" action="modifiervehicule" namespace="/" > <s:select id="imm" label="immatriculation" list="immatriculs" name="immatricul"></s:select> <s:textfield id="kilo" name="kil" label="kilometrage" size="15" ></s:textfield> <s:textfield id="etat" name="etat" label="etat" size="15" ></s:textfield> <s:textfield id="datepicker" name="date" label="date" size="15" ></s:textfield> <s:textfield id="capacite_bagages" name="capacite_bagages" label="capacité de bagages" size="15"></s:textfield> <s:submit style="height:30px; width:125px" name="valider" value="valider"></s:submit> </s:form>
struts.xml
<action name="query" class="action.gestion" method="query"> <result name="success" type="json" > <param name="root">map</param> </result> </action>
make map
map objects instead of strings. example
map<string, object> map= new hashmap<>();
now have put objects inside it, if value null
keep value can after json result returned success
handler. see how exclude properties null
values json result.
Comments
Post a Comment