Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    AdvancedCriteria / CombineCriteria question

    Hello,

    I am using smartGwt 2.5 (according to the jar) which I downloaded from the nightlies on 8th Feb.

    I have been trying to combine two advancedCriteria but seem to be having problems.

    I have two criteria, criteriaOne and criteriaTwo as follows...

    Code:
    AdvancedCriteria criteriaOne = new AdvancedCriteria(OperatorId.OR, new Criterion[] {
                    new Criterion("status", OperatorId.EQUALS, 2),
                    new Criterion("status", OperatorId.EQUALS, 3)});
    criteriaOne.addCriteria(new AdvancedCriteria("incInVat", OperatorId.EQUALS, 1));
    
     AdvancedCriteria criteriaTwo = new AdvancedCriteria(OperatorId.OR, new Criterion[] {
                    new Criterion("status", OperatorId.EQUALS, 2),
                    new Criterion("status", OperatorId.EQUALS, 3)});
    criteriaTwo.addCriteria("paidVat", OperatorId.NOT_EQUAL, 1);
    I would like to combine the two with an OR operator.

    I have tried to do this

    Code:
    criteria = new AdvancedCriteria(criteriaOne);
                    criteria.addCriteria(criteriaTwo);
                    criteria.setOperator(OperatorId.OR);
    but this changes the AND operator in criteriaOne to be OR so this does not have the desired effect.

    I have tried this

    Code:
    criteria = new AdvancedCriteria(DataSource.combineCriteria(criteriaOne,
                            criteriaTwo).getJsObj());
    but this returns the criteria with an AND operator.

    I have also tried this

    Code:
    criteria = (AdvancedCriteria)DataSource.combineCriteria(criteriaOne,
                            criteriaTwo,
                            CriteriaCombineOperator.OR,
                            TextMatchStyle.SUBSTRING);
    but this returns null.

    Could you please tell me how I can combine the two criterias with an OR operator? I appreciate that I could do it manually but I have more complex criterias to combine and would like to use the methods provided.

    Many Thanks

    Jeni

    #2
    Just write

    Code:
    criteria = new AdvancedCriteria(
        OperatorId.OR,
        new Criterion[] { criteriaOne, criteriaTwo }
    );

    Comment


      #3
      Duh!
      Couldn't see it for looking!
      Thank you very much.

      Comment

      Working...
      X