Sunday, September 6, 2015

Validate creation of one master record with one detail record at least

Case
Any new Department must provide at least one Employee.

Implementation Method
  1. Create "Business Component from Tables" for Departments and Employees.
  2. Check the property "Composition Association" at the association.
There are many method to apply the validation of existing one Employee for each Department:
  • Using "Entity Validators" of type "Script Expression"
    Create new "Validator" on the Department of type script Expression and write:
 if(DETAIL_ACCESSOR_NAME.count('ANY_DETAIL_ATTRIBUTE_NAME') >=1)
return true;
return false;
  • Using "Entity Validators" of type"Collection":
    Cretae new entity validators on Department of type "Collection",
    Choose the :
    Operation =  "Count"
    Accessor  = Accessor Name of Employee.
    Atribute   = any attribute
    Operator  = "GreaterOrEqualTo"
    Enter Literal Value = 1
  • Create managed been class implements "BindingContainerValidator" interface and overrides "validateBindingContainer" method:
@Override
public void validateBindingContainer(BindingContainer bindingContainer) {
if(  ( (DCIteratorBinding) bindingContainer.get("DETAIL_ITERATOR_NAME")).getCurrentRow()==null){
throw new ValidatorException(new FacesMessage("Create a new Contact info before commit"));
        }
    }
       then go to page definition properties and set two properties
       CustomValidator="#{YOUR_CUSTOM_VALIDATE_MANAGED_BEAN}"
      SkipValidation="custom"

No comments:

Post a Comment

java - fill distinct objects in ArrayList

If you have a list that contains some objects that it is considered as duplication when two or three fields of these objects are equal. How ...