I blogged a while ago about making a Money class: immutable, some simple facilities in it for parsing from a string, yada, yada, yada. So now I am doing some JSF work with the Money class. I chose to make this thing @Embeddable for now, so if we have something like a price in a listing for instance, we end up with price_amount and price_currency.
If you are going to JSF properly, you want to be able to bind the input of an amount of money to a field of type Money. There are a few problems that come up:
What is needed here is some kind of chaining. Consider: the currency itself can be a property on a bean that has session scope. Then, we could make a custom component that is compound. Now, the currency could be done as a dropdown bound to a list in said session bean, so that if we do want to support multiple currencies in a single session, we can, but then, we can do something where when we go to render, we look at how many currencies are in there, and if the answer is 1, we just render the currency label as an output string, otherwise, we render the dropdown. Might also want to jump into the middle of such a thing and let them select the currency once, for instance, at the order level, then have all line items get their currency from the one selected there.
The last question becomes how to get the value into the domain model, and of course, the answer is a custom converter. The only tricky part is that we are going to want the converter to turn the values around, so for instance, if we are passed a string like $125.00, we will want to call new Money(125.00USD), or parse the symbol, whatever, the idea is that we can use a different representational logic on screen than is mandated by the domain model parser.