Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>IMO, the simplest solution is to create a separate java class say <code>Money</code> that holds both information, the type of money (i.e. Currency) and the value of money.</p> <pre><code>public class Money { private Currency currency; private Double value; public Currency getCurrency() { return currency; } public void setCurrency(Currency currency) { this.currency = currency; } public Double getValue() { return value; } public void setValue(Double value) { this.value = value; } public boolean isValid() { if(getCurrency() == null || getValue() == null) { return false; } // critical logic goes here // sample code if("JPY".equalsIgnoreCase(currency.getCurrencyCode())) { int intValue = getValue().intValue(); double diff = getValue() - intValue; if(diff &gt; 0) { return false; } } /*double fractionValue = value - (value % (currency.getDefaultFractionDigits() * 10)); if(fractionValue &gt; currency.getDefaultFractionDigits() * 10) { return false; }*/ return true; } } </code></pre> <p>After this, create a constraint say <code>@ValidMoney</code> and <code>MoneyValidator</code>.</p> <pre><code>public class MoneyValidator implements ConstraintValidator&lt;ValidMoney, Money&gt; { @Override public void initialize(ValidMoney constraintAnnotation) { // TODO Auto-generated method stub } @Override public boolean isValid(Money value, ConstraintValidatorContext context) { return value.isValid(); } } </code></pre> <p>Example:-</p> <pre><code>public class Bid { @ValidMoney private Money bidAmount; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload