Tapestry
  1. Tapestry
  2. TAPESTRY-572

NumberValidator should accept Strings

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Won't Fix
    • Affects Version/s: 4.0
    • Fix Version/s: 4.1.2
    • Component/s: Framework
    • Labels:
      None

      Description

      Applying NumberValidator to a TextField will allow a number to be validated as a number and stored as a String. However, NumberValidator is not able to take a String and display it as a number. I think this should be a bidirectional process. An example of where this would be useful is the following:

      I'd like to store a number as a String so I don't lose any prepending 0's (which RDBMSs love to throw out) when persisting the data. However, I do want to ensure that only a number is valid input.

        Activity

        Hide
        Kevin Menard added a comment -

        Like I said, I'll go with Paul's approach. It seems to make sense that the validators should handle non-native datatype validation. But, if your assessment of the translator system is correct, then it's really only applicable for read-only values, unless of the proper type, since the translation is only done in one direction. So, if it were intended to be a data marshalling service, its utility is limited.

        Show
        Kevin Menard added a comment - Like I said, I'll go with Paul's approach. It seems to make sense that the validators should handle non-native datatype validation. But, if your assessment of the translator system is correct, then it's really only applicable for read-only values, unless of the proper type, since the translation is only done in one direction. So, if it were intended to be a data marshalling service, its utility is limited.
        Hide
        Jesse Kuhnert added a comment -

        I think the translator services are meant to translate incoming values (which are already strings) in to native/object types whereas validators would be just for validation of input... In your case it seems input validation really is all you need as translation from string -> number -> string wouldn't make any sense. ...

        Paul would know best in either case since he wrote the majority of this infrastructure.

        Show
        Jesse Kuhnert added a comment - I think the translator services are meant to translate incoming values (which are already strings) in to native/object types whereas validators would be just for validation of input... In your case it seems input validation really is all you need as translation from string -> number -> string wouldn't make any sense. ... Paul would know best in either case since he wrote the majority of this infrastructure.
        Hide
        Kevin Menard added a comment -

        That looks like it'd do the trick. I guess I had just hoped that the number translator would handle this fairly common case. But, I may have just missed the point, too. In any event, it probably should break in both directions, rather than work in just one <shrug>.

        Show
        Kevin Menard added a comment - That looks like it'd do the trick. I guess I had just hoped that the number translator would handle this fairly common case. But, I may have just missed the point, too. In any event, it probably should break in both directions, rather than work in just one <shrug>.
        Hide
        Paul Ferraro added a comment -

        I think what you're looking for is the Pattern validator which validates a string against a regular expression.
        http://tapestry.apache.org/tapestry4.1/apidocs/org/apache/tapestry/form/validator/Pattern.html
        Something like this perhaps?
        <binding name="validators" value="validators:pattern=\d+"/>

        Show
        Paul Ferraro added a comment - I think what you're looking for is the Pattern validator which validates a string against a regular expression. http://tapestry.apache.org/tapestry4.1/apidocs/org/apache/tapestry/form/validator/Pattern.html Something like this perhaps? <binding name="validators" value="validators:pattern=\d+"/>
        Hide
        Kevin Menard added a comment -

        I think I actually meant NumberTranslator. I had to dig into my code to verify, but I don't use the T3 validation system at all. Indeed, it looks like the problem is still around with a number translator (<binding name="translator" value="translator:number"/>).

        Should I open a new issue or edit this one?

        Show
        Kevin Menard added a comment - I think I actually meant NumberTranslator. I had to dig into my code to verify, but I don't use the T3 validation system at all. Indeed, it looks like the problem is still around with a number translator (<binding name="translator" value="translator:number"/>). Should I open a new issue or edit this one?
        Hide
        Jesse Kuhnert added a comment -

        I think that NumberValidator has been deprecated in favor of the new validators/translator setup. (where there is no NumberValidator class .....number translators and validators do exist though)

        Show
        Jesse Kuhnert added a comment - I think that NumberValidator has been deprecated in favor of the new validators/translator setup. (where there is no NumberValidator class .....number translators and validators do exist though)

          People

          • Assignee:
            Unassigned
            Reporter:
            Kevin Menard
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development