Results 1 to 2 of 2

Thread: Constraint to check if null?

  1. #1
    Join Date
    Aug 2005
    Location
    London (the English one!)
    Posts
    378

    Default 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. #2
    Join Date
    Aug 2005
    Location
    London (the English one!)
    Posts
    378

    Default 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •