Announcement Announcement Module
Collapse
No announcement yet.
Constraint to check if null? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Constraint to check if null?

    Hi

    I have a case where a property can be null or must be in a range.

    I was thinking of using ifTrue(constraint1, constraint2)

    where constraint1 would be "property is not null"...
    Question how do you specify that one?

    does the present() means 'not-null'?

    Thanks

    Benoit

  • #2
    A bit more precise

    Allow me to be a bit more precise.
    Code:
    public class MyClass {
      private BigDecimal quantity;
      private BigDecimal maxQuantity;
    }
    I want to be able to say:
    - IF quantity is not null, then quantity must be > 0 AND less or equal to maxQuantity.
    - if quantity is null, no requirement for a rule.

    I thought of using
    Code:
    new Rules(MyClass.class) {
     protected void initRules() {
      add("quantity", ifTrue( present(), 
        all(new Constraint[] { 
           required(),
           gt(new BigDecimal(0.0)),
           gteProperty("maxQuantity", "quantity") }));
    However this seems to say that maxQuantity is NOT a property of BigDecimal, but I cannot figure out why it seems to call it on a BigDecimal rather than MyClass???

    Could somebody enlighten me? THANKS

    Benoit

    Comment

    Working...
    X