pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anton dos santos <adsan...@free.fr>
Subject TextInput and Validator issues
Date Sun, 06 Mar 2011 09:11:54 GMT
Hi
I am trying to use a TexInput with an IntValidator in a TableViewRowEditor but I can't get
it to do 
what I want. I'd like to have an input field where user can enter only digits and the input
field 
can be empty (in that case background can become red if input is mandatory or stay white).

When I set StrictValidation="true", then it is impossible to have an empty InputField; user
can't do 
following : erase current value in input and enter a new value. User has to enter the new
value and 
then remove the old, which is not intuitive (at least to me).

Then I tried StrictValidation="false"; it seems to work, but user can also enter characters
(which 
is not what I want) and when he hits return key to end editing, an exception is thrown:
java.lang.NumberFormatException: For input string: "145jhk"
         at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
         at java.lang.Long.parseLong(Long.java:419)
         at java.lang.Long.parseLong(Long.java:468)
         at org.apache.pivot.beans.BeanAdapter.coerce(BeanAdapter.java:897)
         at org.apache.pivot.beans.BeanAdapter.put(BeanAdapter.java:286)
         at org.apache.pivot.json.JSON.put(JSON.java:152)
         at org.apache.pivot.wtk.TextInput.store(TextInput.java:841)
         at org.apache.pivot.wtk.Container.store(Container.java:613)
         at org.apache.pivot.wtk.content.TableViewRowEditor.endEdit(TableViewRowEditor.java:254)
Here, maybe TextInput#store() shoudn't be invoked when TextInput#isTextValid() == false ?

I also tried StrictValidation="true" and an intValidator that accepts empty input by overriding

isValid():
     public boolean isValid(String text) {
         final ParsePosition pos = new ParsePosition(0);
         Object obj = format.parseObject(text, pos);
         if( obj == null || text.length() == 0) {
           return true;
         }

         // the text is only valid is we successfully parsed ALL of it. Don't want trailing
bits of
         // not-valid text.
         return obj != null && pos.getErrorIndex() == -1 && pos.getIndex()
== text.length();
     }
this works fine until user erases everything in the TextInput, from then on use can enter
any 
character, he is no longer limited to digits.

What else could I try ?

Regards
Anton

Mime
View raw message