ADF Basics: Duplicate Record Validation Using Model Level Business Rules

Sharing is Caring
Hello All
Hope you all are doing well 🙂
This post is about duplicate record validation, When we are creating any data entry form, at that time preventing duplicate entries for some of the attributes is very basic validation requirement.Suppose We are creating a form to make new Departments entry and  there should not be two departments with same name so for this type of validation we need not to write single line of code in Oracle ADF as there are predefined business rules for basic validation

In this post I am discussing how to apply model level business rule for duplicate record validation, Here I am using Departments table of HR Schema to create business components (EO,VO)

Open EntityObject and create a alternate key for DepartmentName attribute, On this alternate key we will apply business rule

Click on Buisness Rules tab, Select DepartmentsEO and Click on Green plus icon

Select Unique Key Validation in type for Alternate Key

Go to Failure Handling tab and put a message that you want to appear in case of validation failure

Now drop Departments ViewObject on page as form from data control and drop createInsert operation as button and set autoSubmit true for DepartmentName attribute (to post it’s value to model for immediate validation)

<af:panelBox text="Duplicate Record Validation" id="pb1" showDisclosure="false" background="medium"
                                 inlineStyle="width:550px;" ramp="highlight">
                        <f:facet name="toolbar">
                            <af:button actionListener="#{bindings.CreateInsert.execute}" text="CreateInsert"
                                       disabled="#{!bindings.CreateInsert.enabled}" id="b1"/>
                        </f:facet>
                        <af:panelFormLayout id="pfl1">
                            <af:inputText value="#{bindings.DepartmentId.inputValue}"
                                          label="#{bindings.DepartmentId.hints.label}"
                                          required="#{bindings.DepartmentId.hints.mandatory}"
                                          columns="#{bindings.DepartmentId.hints.displayWidth}"
                                          maximumLength="#{bindings.DepartmentId.hints.precision}"
                                          shortDesc="#{bindings.DepartmentId.hints.tooltip}" id="it1"
                                          contentStyle="width:150px;">
                                <f:validator binding="#{bindings.DepartmentId.validator}"/>
                                <af:convertNumber groupingUsed="false" pattern="#{bindings.DepartmentId.format}"/>
                            </af:inputText>
                            <af:inputText value="#{bindings.DepartmentName.inputValue}"
                                          label="#{bindings.DepartmentName.hints.label}"
                                          required="#{bindings.DepartmentName.hints.mandatory}"
                                          columns="#{bindings.DepartmentName.hints.displayWidth}"
                                          maximumLength="#{bindings.DepartmentName.hints.precision}"
                                          shortDesc="#{bindings.DepartmentName.hints.tooltip}" id="it2"
                                          contentStyle="width:150px;" autoSubmit="true">
                                <f:validator binding="#{bindings.DepartmentName.validator}"/>
                            </af:inputText>
                            <af:inputText value="#{bindings.ManagerId.inputValue}"
                                          label="#{bindings.ManagerId.hints.label}"
                                          required="#{bindings.ManagerId.hints.mandatory}"
                                          columns="#{bindings.ManagerId.hints.displayWidth}"
                                          maximumLength="#{bindings.ManagerId.hints.precision}"
                                          shortDesc="#{bindings.ManagerId.hints.tooltip}" id="it3"
                                          contentStyle="width:150px;">
                                <f:validator binding="#{bindings.ManagerId.validator}"/>
                                <af:convertNumber groupingUsed="false" pattern="#{bindings.ManagerId.format}"/>
                            </af:inputText>
                            <af:inputText value="#{bindings.LocationId.inputValue}"
                                          label="#{bindings.LocationId.hints.label}"
                                          required="#{bindings.LocationId.hints.mandatory}"
                                          columns="#{bindings.LocationId.hints.displayWidth}"
                                          maximumLength="#{bindings.LocationId.hints.precision}"
                                          shortDesc="#{bindings.LocationId.hints.tooltip}" id="it4"
                                          contentStyle="width:150px;">
                                <f:validator binding="#{bindings.LocationId.validator}"/>
                                <af:convertNumber groupingUsed="false" pattern="#{bindings.LocationId.format}"/>
                            </af:inputText>
                        </af:panelFormLayout>
                    </af:panelBox>

Click on CreateInsert button and add a duplicate DepartmentName and this is the output

Duplicate Record Validation

Sample ADF Application (Jdev 12.1.3)- Download

Cheers 🙂 Happy Learning

Related Posts

An Oracle ACE, Blogger, Reviewer, Technical Lead working on Oracle ADF

0 thoughts on “ADF Basics: Duplicate Record Validation Using Model Level Business Rules”

Leave a Reply

Your email address will not be published. Required fields are marked *