Results 1 to 2 of 2

Thread: How to set a Constraint dependent on another Constraint

  1. #1
    Join Date
    Aug 2004
    Location
    Brisbane (Australia)
    Posts
    57

    Default How to set a Constraint dependent on another Constraint

    Hi all,

    I am having a problem with a validation scenario I am coding up. I have a (simplified) POJO as follows:

    Code:
    public class UserDefaults{ 
        private boolean isCustomer;
        private String businessName;
    
    .. etc, etc.
    }
    What I want to do is create a Constraint that requires the businessName property to be valid, but only if the isCustomer property is true (otherwise don't test the businessName property).

    I tried to do this in my RulesSource implementation:

    Code:
    private Rules createUserRules() {
        return new Rules(BatchConsSettings.class){
            protected void initRules() {
                Constraint isCustomer = eq("isCustomer", Boolean.TRUE);
                    
                this.add("businessName", ifTrue(isCustomer, required("businessName")));
            }
        };
    }
    The problem is - this doesn't work, because the isTrue constraint is being evaluated against the value of the businessName property (which is a String, of course) and as such throws an exception because the String value has no such property "isCustomer".

    Unfortunately, I can't do this...

    Code:
                this.add(ifTrue(isCustomer, required("businessName")));
    ...because the add method only permits CompundConstraints and PropertyConstraints, not basic Constraints.

    So I'm kind of stuck with this. Is such a chained constraint even possible using the existing Constraint classes, or does it require some sort of custom implementation?

    -Scott

  2. #2
    Join Date
    Dec 2004
    Posts
    5

    Default

    I have the same problem !!!

Similar Threads

  1. Replies: 1
    Last Post: Aug 18th, 2006, 11:04 PM
  2. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  3. Replies: 4
    Last Post: Sep 27th, 2005, 11:31 PM
  4. Replies: 4
    Last Post: Aug 17th, 2005, 04:42 AM
  5. Integer Constraints in RulesSource?
    By steve_smith in forum Swing
    Replies: 13
    Last Post: Nov 3rd, 2004, 03:55 PM

Posting Permissions

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