Skip to Content
avatar image
Former Member

Seperator issue with input field and float

Hello all,

i got a problem with an input text field in my webdynpro application. This textfield is used to enter an float digit like 50.3, i have bound the field to a note with the value float and everything works fine, almost.

There is just one strange thing happend. If the user is logged on with german language settings and he tipes 50.3 into the field i got the number 503, if he puts 50,3 into the field a got the right value 50,3. The same happens the other way arround if the user is locked on with english language settings.

Is there anyway to tell the application that the node should accept both seperators '.' as well as ',' and not just kick out the a wrong seperator if the language doesnt fit? If somebody has an idea, that would be great 😊

Regards,

Andre

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Jul 06, 2009 at 01:23 PM

    Hi Andre

    Actually the float type depends on the user's locale and system's regional settings. Your task as I understand is just to accept only one format and to mark another one with 'invalid format' error message, right?

    If you want you can make the field as String and perform your own field parsing/validation which will accept the both variants in format. Or it will accept one format and deny another one.

    Do you use Non-Validating actions in your WD application?

    BR, Sergei

    Add comment
    10|10000 characters needed characters exceeded

    • >@ Sergei

      >What do you mean with "Non-Validating actions". Í have never heard from that, okay maybe i'm not that at all in WD.

      By default actions that you create in WD View are Validating. This means that when the action is executed on a server side (let say user pressed some button on the View) Webdynpro tries to validate values typed by user in UI fields and other controls against field types. If typed value does not match to a type such fields will be marked in red as invalid and error messages will be shown.

      As you did not see any error messages even when the format of typed value was wrong my first impression was you disabled the feature and marked the action as Non Validating.

      BR, Sergei

  • avatar image
    Former Member
    Jul 06, 2009 at 01:38 PM

    Hi Andre,

    if u want to allow the ',' in your input text field. follow the bellow steps.

    1)bind that Input field with context attribut of String Datatype.

    2) create one custom method with boolean return type and create one string parameter in that method and paste the foolowing code in that method.

    String strValidChars =

    "0123456789.,";

    char strChar;

    boolean blnResult = true;

    if (inputValue.length() == 0)

    return false;

    for (int i = 0; i < inputValue.length() && blnResult == true; i++)

    {

    strChar = inputValue.charAt(i);

    if (strValidChars.indexOf(strChar) == -1)

    {

    blnResult = false;

    }

    }

    return blnResult;

    3) call this method in ur implimentation.

    4) next check the data entered is correct or not.

    I hope this will work for you.

    if there is any issue let me know.

    thanks&Regards,

    bhargava

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 07, 2009 at 06:03 AM

    Hi,

    One alternative for your problem is:

    Change the type of the context attribute, which you bind to your input filed from float to String.

    And before using the value just parse it to float.

    String strSalary = wdContext.currentContextElement().getSalary();
    if(null != strSalary)
    {
      strSalary = strSalary.replaceAll(",",".");
      float salary = Float.parseFloat(str);
    }
    

    Regards,

    Jaya.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 07, 2009 at 08:30 AM

    Hi Andre,

    One workaround for this is to set the locale through the application. No matter whether the user logs in through German or English settings the format will always remains same.

    Locale loc = Locale.getDefault();

    loc = Locale.US;

    Locale.setDefault(loc);

    However in this case you will lose the current locale from which actually the user logged in.

    Regards,

    Ponraj M

    Add comment
    10|10000 characters needed characters exceeded