Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

is this a misuse of a converter. A JSF2 Project.  RSS feed

 
Christopher Whu
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tend to find that i don't always use java technologies correctly. Do you think i am misusing the converter technology here.

I am working on a project that uses is dependent on measurement.

I am storing all my measurements in the database as inches and square inches. The client wants them displayed as feet and square feet. I wrote a converter for this and i am using it on the JSF pages.

 
Tim Holloway
Bartender
Posts: 18709
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, on this forum, we've got people who practically specialise in misusing things! As I've been known to complain, apparently JSF's basic utility is so simple that they feel obliged to throw up a rat's nest of dives into internal APIs and data structures, exits, listeners, etc., etc., etc. just to make it look a like a "real" program.

A converter's first duty is to manage the transformation of an internal object to and from the HTML (text) representation of that object. Which is generally the object's value.

Obviously a secondary duty is to support locale, as witness the options for numberformat conversion and datetime conversion.

It's not a very large or awkward step to go from there to add unit of measurement transformations. So you won't get any condemnation from me. In fact, I have a project where a similar situation may arise between gallons and liters, only more so, since the system in use would depend on the user.

The only caveat that I would add is that as much as possible, you should ensure that the transformations are lossless and repeatable. Otherwise, you may see alterations in data values even when the item in question isn't being directly modified by the user, just on account of how postbacks work. That's not a problem unique to user-written converters, however. Just think of handling a binary "2.666666..." on a double-precision converter with 2 digit display precision.
 
Christopher Whu
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You so much Tim... You are always a big help...

I am a "lone" programmer for most of the year, i am always worried about doing things in a way that will offend others who have to read my code...

I apologize for my English (second language)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!