This discussion is archived
7 Replies Latest reply: Oct 15, 2012 1:10 AM by Mahmoud A. ElSayed RSS

Re-Validate Master EntityObject

Mahmoud A. ElSayed Newbie
Currently Being Moderated
Hi,

I want to re-validate Master EO again when adding new record is inserted in detail EO
I wrote the below code in EntityImpl class of detail EO

public void postChanges(TransactionEvent transactionEvent) {
if (this.getPostState() == STATUS_NEW || this.getPostState() == STATUS_MODIFIED) {
EntityImpl masterEO= (EntityImpl )this.getMasterEO();
if (eventsEO != null) {
masterEO.postChanges(transactionEvent);
}
}
super.postChanges(transactionEvent);
}

the previous code revalidate master EO when any attribute is changed in master, but if added a record in child without change master data validation doesn't occur in master EO.

I want to re-validate master EO because I created business rule depend on count of rows in detail EO.

BR
  • 1. Re: Re-Validate Master EntityObject
    Timo Hahn Oracle ACE
    Currently Being Moderated
    This sounds a bit strange to me. If your master needs re validation when a child has changed it should not the master. the child should not have been changed (or added) in the first place.

    Can you elaborate on the use case?

    Timo
  • 2. Re: Re-Validate Master EntityObject
    Mahmoud A. ElSayed Newbie
    Currently Being Moderated
    My use case

    I have Master EO and Detail EO.

    I created validation in master EO to assure that number of records in detail EO doesn't exceeds value entered in an attribute of master EO
    using expression

    if( DetailEO.count(DetailAttr) <= NoOfRecordsAttr )
    return true;
    else return false;

    when inserting new records in details exeeds value in NoOfRecordsAttr , the validation doesn't fire until I change any data in master EO

    BR
  • 3. Re: Re-Validate Master EntityObject
    Mahmoud A. ElSayed Newbie
    Currently Being Moderated
    I override postChanges()method in detail EO to call postChanges() method of master EO in case of adding new records in detail EO, but postChanges() doesn't re validate master EO because its state hasn't been changed.

    public void postChanges(TransactionEvent transactionEvent) {
    if (this.getPostState() == STATUS_NEW || this.getPostState() == STATUS_MODIFIED) {
    EntityImpl masterEO= (EntityImpl )this.getMasterEO();
    if (eventsEO != null) {
    masterEO.postChanges(transactionEvent);
    }
    }
    super.postChanges(transactionEvent);
    }

    So is there another way to re validate master EO.
    I tried to use validate() method but unfortunately it is protected.


    BR
    Mahmoud
  • 4. Re: Re-Validate Master EntityObject
    Timo Hahn Oracle ACE
    Currently Being Moderated
    I would do it three other easy around. Don't allow to add new child records if three max number of child records its reached. This way you don't have to allow the entry of a child record which you then have to rollback.
    It should be easy to implement this. If you use a button in the ui to add a new child you only need to set an EL to the button which checks if there the no if child's is lower add the allowed number.

    Timo
  • 5. Re: Re-Validate Master EntityObject
    Mahmoud A. ElSayed Newbie
    Currently Being Moderated
    Yes, it is easy to apply in UI , but I want to apply it in Model (EO ) because it is the correct place to implement business rules.

    Also , Note in some situations you may insert a new records programatically in detail EO , you will repeat your code everywhere you want to insert new records.

    Mahmoud
  • 6. Re: Re-Validate Master EntityObject
    Timo Hahn Oracle ACE
    Currently Being Moderated
    OK, in this case you should put the rule into the child EO and use an groovy script to check if you can add another child record. You can e.g. add a method to the master which returns true or false and call that via groovy.

    Timo
  • 7. Re: Re-Validate Master EntityObject
    Mahmoud A. ElSayed Newbie
    Currently Being Moderated
    Thanks Timo,

    I will apply your suggestions.

    Mahmoud

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points