cancel
Showing results for 
Search instead for 
Did you mean: 

Seperator issue with input field and float

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

siarhei_pisarenka3
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Thx, to all for their help!

I changed the node from "float" to "string" and did my own validation

Regards,

Andre

@ Sergei

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

siarhei_pisarenka3
Active Contributor
0 Kudos

>@ 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

Answers (3)

Answers (3)

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

Former Member
0 Kudos

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