Monday, 30 April 2018

Step 7: Fine tune Model components to refine how the data displays

You refine the employee business components, add validation and modify how the UI displays.
  1. In the Applications window, expand the Model > Application Sources > demo.model and double-click the Employees entity node.
    The full definition opens in the editor area. Select the Attributes tab to see all the employee attributes.
    This screenshot shows the Applications window with the Model project expanded and the Employees entity selected on the left side of the window. On the right, the screenshot displays the editor area, the Attributes tab selected, and displays all the employees attributes.
  2. Select the Salary attribute then click the Validation tab below.
    To the right-click the green plus sign to add a new validation rule.
    This screenshot shows the employees attributes in the editor area, the Salary attribute selected in the top pane, Validatation Rules tab selected in the bottom pane, and the add new validatation icon selected.
  3. Set the Name to SalaryRange, the Type to Range, the Minimum Value to 0 and the Maximum Value to 50000.
    There are many operator you could you to implement your validations including, compare, length, restrictive list and others.
    This screenshot shows the Add Validation Rule for the selected attribute, where you can specify the validation rule as mentioned in the previous paragraph.
  4. Click the Failure Handling tab and then set the error message text.
    Set the Message Text property to The Salary is out of range (must be between 0-50k).
    This screensot shows the Add Validation Rule for the selected attribute, the Failure Handling tab selected, and the Message Text property entered.
  5. Save All your work.
  6. Next, refine the display properties of the HireDate.
    Select the HireDate attribute and then click the UI Hints tab.
    Set the Label to Hired On, the Format Type to Simple Format, and then select a Format you like.
    This screenshot shows the editor area with employees attributes, HireDate attribute selected in the top pane, UI Hints tab selected in the bottom pane, and few fields entered with the details as mentioned in the previous paragraph.
  7. Save all your work and then click the x in the Employees.xml tab.
    This screenshot shows the editor area and highlights the close button of the Employees.xml tab.
  8. Next, in the Applications window, double-click the EmployeesView component.
    In the editor, select the Attribute tab, and then the JobId.
    Click the List of Values tab and then click the green plus sign.
    This screenshot shows the Applications window and the editor area. On the left, this screenshot displays the Applications window with expanded Model project and EmployeesView component selected. On the right, displays the editor area of the EmployeesView.xml. The editor area is divided into three parts. On the left pane, Attributes tab selected, on the top right pane, JobID attribute selected, and in bottom right pane, List of Values and create new list of values icon selected.
  9. In the Create List of Values pane, set the Name to JobsLOV.
    Then in the List Data Source, click the green plus sign and select the JobsView.
    Click Ok to return.
    This screenshot shows the Create List of Values dialog with all the other values selected as specified in the previous paragraph and the View Accessors dialog.
    Back in the LOV pane, set the List Attribute to JobId .
    This screenshot shows the Create List of Values dialog with List Attribute under Configuration tab set to JobId.
  10. Now set the UI Hints for the LOV.
    Click the UI Hints tab and shuttle the JobTitle to the Selected side to display it in the LOV.
    At the bottom of the pane, you can set a limit for the number of records to retrieve. Deselect the Query Limit to remove that restriction.
    Then click OK to complete the LOV.
    Save all your work
    This screenshot shows the Create List of Values dialog with UI Hints tab selected. The UI Hints tab list the available attributes on the right under Available and when selected, shows the attributes on the left under Selected. The Query Limit in the bottom pane is highlighted.
  11. Now update the page to reflect the newly added JobId LOV.
    Go back to the HR.jsf page and in the Structure window, expand the af:panelBox - Details > af:panelFormLayout.
    Select and delete the af:inputText - JobId.
    This screenshot shows the Structure window of the jsf page with inputText - JobID selected as specified in the previous paragraph.
  12. Now using the Data Controls, add the JobId back to the page (which will bring along the LOV). The key thing to remember is the attribute you add must come from the same data control as it did originally (in our case EmployeesView4).
    Open the Data Controls window and expand the AppModuleDataControl > DepartmentView1 > EmployeesView4 and select the JobId.
    Drag and drop it between the HireDate and Salary.
    In the popup menu select List of Values > ADF LOV Choice List.
    This screenshot shows the Data Controls window and the Structure window. JobId data control from the Data Control window is dragged and dropped to the Structure window under the panelFromLayout, which was selected in the previous step. The screenshot also shows the List of Values  - ADF LOV Choice List selected from the popup menu.
    If the af:inputComboboxListOfValues is not positioned correctly, drag it to the correct place.
    Save all your work.
    This screenshot shows the Structure window with inputComboboxListOfValues selected, which was added in the previous step.
  13. The last thing we need to do is add commit and rollback functionality.
    In the Data Controls, expand the AppModuleDataControl > Operations nodes.
    Drag the Commit operation to the Structure window and drop it on the f:facet - appNav node.
    In the popup menu select ADF Link.
    This screenshot shows the Commit operation from the Data Controls window is dragged and dropped to the appNav facet in the Structure window as ADF Link.
    Then, using the same gestures, add a Rollback right below it
    This screenshot shows the Structure window with the Rollback operations added to the appNav facet as ADF Link.
    To finish this step add a Spacer (from the Components window) between the two links. Use the search area at the top of the window to find the Spacer component.
    This screenshot shows the Structure window ont he left and the Components window on the right that displays the Spacer component. The Structure window also displays a Spacer component added between the Commit and Rollback operations.
  14. Save your work and compile the changes. Since we added new validation, right-click in the HR.jsf page and select Run.
    When the browser opens, navigate to the Details panel box, click the widget next to the JobId and notice the drop down displaying all the job names. Change the job to a different value.
    Also notice the label and format for the HireDate field match what we set earlier.
    This screenshot shows the browser page that displays the data on the left pane, all the four panel boxes on the right pane. In the Details panel box, the Hired on field is highlighted. The JobId field displays a list of values.