1

The problem that I can't insert double values with point (example 2.2), however I can insert them with comma (example : 2,2).

but when I want to edit them using (JSP and Ajax), they appear with (point) even if I stock them with comma, so that I have to edit all values !

the scenario is as follows : I want to edit some double values in my application (hibernate and struts2),i pass the values from action to JSP :

private Service Service;
    private Vehicule v;
    private Map<String, Object> map= new HashMap<>();

    public String query()
    {

            Service = new ServiceImpl();
            v = new Vehicule();
            v= Service.getVehiculeByImmat(field1);
            map.put("date", v.getdate().toString());
    map.put("kilometrage", v.getKilometrage());


    return "success";

    }

then I show them in my JSP :

$(document).ready(function(){

      $('#field1').change(function(){


          var selectedValue = $('#field1').val();
            if ($.trim(selectedValue).length > 0) 
             {
          alert(selectedValue);
                $.ajax(
                {
                    type: 'POST', 
                    url  : "<s:url action='query'/>",
                    dataType : 'json',
                    data: { field1: selectedValue},
                    success: function(result){

                        $.each(result, function(key,value)
                        {                      $("#"+key).val(value);
                                    } );

                },

                 });

            }

        }
      );


    });

struts.xml:

<action name="query" class="action.GestionVehicules" method="query">
          <result name="success" type="json">map</result>
    </action>

my question : it's possible to insert the double values with point ?

Roman C
  • 49,761
  • 33
  • 66
  • 176
lilyana
  • 141
  • 1
  • 4
  • 17

1 Answers1

0

The default locale is different than expected on the client side. Fractional numbers format is also different for those locales. You could set a US locale to the action context to use it when serialized to JSON. According to this locale it uses a dot for fractional part separator and comma for grouping.

ActionContext.getContext().setLocale(Locale.US);  

Do it before returning a result.

Roman C
  • 49,761
  • 33
  • 66
  • 176
  • oh thank you sir for your attention, it's very kind of you, but my problem is that I have to enter the values ( in the form) with comma for it to be recognized by the application, because if i use the point,i just find null values ​​in my data base, and if i show the values from the database ,they appear with point so i have to edit them .... I wish to insert them with point to avoid these problems – lilyana Apr 15 '14 at 11:18
  • You might find this useful to determine your language http://en.wikipedia.org/wiki/Decimal_mark – Roman C Apr 15 '14 at 13:41
  • This link has some locales and corresponding decimal separators http://docs.oracle.com/cd/E19455-01/806-0169/overview-9/index.html – Roman C Apr 15 '14 at 13:49
  • where should i make those Decimals ? – lilyana Apr 15 '14 at 14:49
  • Look at the `Locale` class, it has static members for those listed locales like `Locale.US` or you can create a [custom locale](http://stackoverflow.com/a/10019105/573032). – Roman C Apr 15 '14 at 14:57
  • ya , I want to know how and where can I call this class,i searched but without any results,thank you in advance sir. – lilyana Apr 15 '14 at 17:24
  • Anywhere in the action before returning a result. – Roman C Apr 15 '14 at 17:36
  • i use it, but i still have the same problem ! – lilyana Apr 16 '14 at 15:16