This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Jun 7, 2011, 10:04 AM
66 Posts

How to get value from InputField (XspInputText) that is Number ?

  • Category: Other
  • Platform: All
  • Release: 8.5.2
  • Role: Developer
  • Tags:
  • Replies: 2
Sounds like a stupid question but I cant figure out the correct way of getting numeric value from XspInputText component in JAVA. 
 
On the simple xpage I have a Editbox field which is marked as Number. Then I have a button that submits the form and in java code I need to read the number and process it. Simple task ... but.
 
In JAVA code I can find the component (Edit box) by name and can read value using following methods:
 
1.  myComponent.getValue() 
 This method  returns generic typeless Object so I have to cast the value to proper type. The value entered can be decimal or non decimal (so I'm using double type in my JAVA code ), but when user enters non decimal value the type cast to double fails saying the following
 
07.06.2011 11:44:27   HTTP JVM: java.lang.ClassCastException: java.lang.Long incompatible with java.lang.Double
 
When user enters decimal value, the getValue() returns Double type.
 
Seems that Domino converts the value to type based on value itself. Integer value returns Long type, decimal value returns the correct Double type.  Thats crazy ... How to heandle this??
 
2.  myComponent.getValueAsString()  
 This returns value as a text which seems to be fine, I can use Double.parseDouble(xxx) but ... if user enters the value higher that thousand, the text value returns thousand separator as space char e.g. '12 500' so when parsing it fails so I have to remove spaces first. The same is for decimal separator, where EditBox allows both ...  dot and comma but parser allows just one, otherwise it fails. To avoid these I have to fix the value first which is annoying ...
 
I have to be missing something significant here ... :-(  Can someone point me to easy way of safe handling the numeric value?
 
Thanks a lot!! 
Jun 7, 2011, 2:30 PM
33 Posts
Re: How to get value from InputField (XspInputText) that is Number ?
Hi,
I think that myComponent.getValue() returns already converted value. So if you don't like the way xpages are doing this conversion you can write custom converter or just grab the raw value received.
You can do this by calling myComponent.getSubmittedValue().
Jun 7, 2011, 3:18 PM
66 Posts
Re: How to get value from InputField (XspInputText) that is Number ?
 Yes its converted, but final type depends on what userentered ... and thats the problem. I cant influence whether user enter integer or double, so Domino converts value to respective JAVA class. I know I can convert value manualy I can really do a lot of things but the point is that its very general thing so why should I do some workarounds? JAVA is static typed language so it really matters whether the component.getValue() returns Long or Double. 

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal