Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Best Practice question: Storage and display of distance data (km and mi)

    Hi Isomorphic,

    I've been storing kilometer-distance data as number in the DB so far.
    Now the system should also be able to support miles.
    I think the only good solution is to normalize the data to kilometers and keep storing it this way. Do you agree?

    The big question then is how/where to do the normalizing (e.g. 10->16 when storing, 16->10 when fetching).
    I have many fields that store distances and if possible the change should be as little as possible. I'll have the setting if the user is using km or mi available everywhere via a static method in the clientside and in the session on the serverside.

    My gut feeling says: "Use RequestTransformer and ResponseTransformer" clientside to take action if the user is using mi. (I recently started using them, therefore this might be an instance of "every problem looks like a nail if the tool you like the most is a hammer")

    Or would you do something on the FormItem / ListGridField level? If so, what?

    Thank you & Best regards
    Blama

    #2
    You could go with that approach, and it would work fine. There is potentially some awkwardness around places where you are already using Request/ResponseTransformer, and need to ensure that the logic to transform distances is included in transformers installed for other reasons.

    Another approach would a SimpleType with formatting and parsing routines that look at the app-wide setting for distance. This is probably cleaner for the above-stated reasons, especially since you will probably already want a SimpleType anyway, just so that you only have to define the logic to add "mi" or "km" in one place.

    Comment


      #3
      Hi Isomorphic,

      thanks for the fast answer. This means a simpleType with customSelectExpression and customUpdateExpression, correct? In there I'd do the necessary computations via Velocity, correct?
      Is there some way to use java here as well instead of Velocity?

      Best regards
      Blama

      Comment


        #4
        No, none of that. Please see the docs for SimpleType - you can define a custom parsers and formatters client side.

        Comment


          #5
          Hi Isomorphic,

          thanks a lot. This did the trick. Once again amazing how declarative everything can be if you use the framework correctly.

          Best regards
          Blama

          Comment

          Working...
          X