Search code examples
formsjsf-2oracle-adfjdeveloper

Create ViewObject as placeholder for form parameters


Background

Trying to create a ViewObject (using JDeveloper 11.1.2.3) that can be dropped on a page to create a form such as:


Form with no inputs


The form parameters must be submitted to a custom reporting framework. In the ViewObject, certain attributes must be linked to List-of-Value selectors, or have its data type picked up from the ViewObject automatically. The developer should be able to drag-and-drop the ViewObject to create a functional form.

This would allow the form to perform input validation using the ViewObject, and allow List-of-Value objects to be used as well.

Problem

There is no entity that backs the ViewObject. There is no SQL that drives the ViewObject. The ViewObject doesn't really need programmatic access, nor is it a static list. It is simply meant to be a container for parameters that can be subjected to validation rules. When a developer drops such a ViewObject on the form, it creates a form with no visible input fields:


Form with inputs


The code behind the scenes resembles:

  <af:inputText value="#{bindings.ManagementCentre.inputValue}"
                label="#{bindings.ManagementCentre.hints.label}"
                required="#{bindings.ManagementCentre.hints.mandatory}"
                columns="#{bindings.ManagementCentre.hints.displayWidth}"
                maximumLength="#{bindings.ManagementCentre.hints.precision}"
                shortDesc="#{bindings.ManagementCentre.hints.tooltip}"
                id="report_P_MANAGEMENT_CENTRE">
  </af:inputText>
  <af:inputText value="#{bindings.ClinicServiceCentreName.inputValue}"
                label="#{bindings.ClinicServiceCentreName.hints.label}"
                required="#{bindings.ClinicServiceCentreName.hints.mandatory}"
                columns="#{bindings.ClinicServiceCentreName.hints.displayWidth}"
                maximumLength="#{bindings.ClinicServiceCentreName.hints.precision}"
                shortDesc="#{bindings.ClinicServiceCentreName.hints.tooltip}"
                id="report_P_CLINIC_SERVICE_CENTRE">
    <f:validator binding="#{bindings.ClinicServiceCentreName.validator}"/>
    </af:inputText>

The code for the submit button runs a managed bean to extract the form parameters and pass them into the report (via a report framework):

  <af:commandButton text="Run Report" id="submitReport">
    <af:fileDownloadActionListener method="#{reportBean.run}" />
  </af:commandButton>

Question

How do you create such a ViewObject that can perform validation but does not need to be backed by a data source?


Solution

  • Solution

    You have to:

    • Create a view object to be programmatic, with the desired attributes.
    • Configure the view object with validation rules.
    • Configure the Application Module.
    • Create the web page form.
    • Update the page binding to create a new row.

    Create View Object

    Create the view object as follows:

    1. Type Control+n to open the New Gallery.
    2. Search for and select View Object.
    3. Click OK.
    4. Set Package, Name, and Display Name appropriately.
    5. Set Data Source to Programmatic.
    6. Click Next.
    7. Click New and provide a meaningful attribute name.
    8. Click OK.
    9. Add the remaining attributes.
    10. Click Next.
    11. Set Updatable to Always for all attributes.
    12. Set Type to the appropriate data type.
    13. Click Finish.

    Configure Validation Rules

    Configure the validation rules as follows:

    1. Click the Attributes finger tab.
    2. Select the desired attribute.
    3. Click the Validation Rules tab.
    4. Click the + icon within the Validation Rules section.
    5. Set the Rule Definition as required.
    6. Set the Error Message as required.
    7. Repeat to add as many validation rules as necessary.

    At this point a view object has been configured and the List of Values tab can be used to reference query-based LOVs.

    Configure Application Module

    Configure the application module as follows:

    1. Double click the application's application module.
    2. Select the Data Model finger tab.
    3. Shuttle the view object from Available View Objects to Data Model.
    4. Remove the 1 suffix.
    5. Save the application.

    Note: If the view object is not visible, restart JDeveloper.

    Create Web Page Form

    Create a web page for the form as follows:

    1. Create a new JSF page for the view object.
    2. Refresh the Data Controls to see the view object instance.
    3. Drag and drop the view object onto the page.
    4. Select Form » ADF Form.
    5. Check Include Submit Button.
    6. Click OK.

    The web page is created.

    Update Page Binding

    The attributes for the view object cannot be changed unless there is a "row" created for the view object instance. Creating this in-memory row must happen before the page content is displayed. Accomplish this as follows:

    1. Expand the Data Controls to reveal the view object's Operations.
    2. Drag Create into the footer facet.
    3. Select ADF Button.
    4. Right-click on the page.
    5. Select Go to Page Definition.
    6. Click + beside Executables.
    7. Select invokeAction.
    8. Click OK.
    9. Set id to: create
    10. Set Binds to: Create
    11. Click OK.
    12. Set Refresh to: prepareModelIfNeeded
    13. Save all.

    Validation is applied and data-driven LOVs can be used.

    Remove the "Create" button.