Skip Headers

Oracle® Application Development Framework Developer's Guide 10g Release 3 (10.1.3) B25386-01 |
| Home | Solution Area | Contents | Index

Previous | Next |

# 10.6 Creating a Form or Table Using a Method that Takes Parameters

There may be cases where a page needs information before it can display content. For these types of pages, you create the form or table using a returned collection from a method that takes parameters. The requesting page needs to supply the value of the parameters in order for the method to execute.

For example, the form on the SREdit page is created using the returned collection from the `findServiceRequestsById(Integer)` method. Instead of returning all service requests, it returns only the service request the user selected on the previous page. The command link on the previous page sets the parameter (`Integer`), which provides the service request's ID. For more information about using a command component to set a parameter value, see Section 10.4, "Passing Parameter Values to Another Page Using a Command Component".

## 10.6.1 How to Create a Form or Table Using a Method That Takes Parameters

To create forms or tables that require parameters, you must be able to access the values for the parameters in order to determine the record(s) to return. For example, before creating the your form or table, you may need to add logic to a command button on another page that will set the parameter value on some object that the method can then access. For more information, see Section 10.4, "Passing Parameter Values to Another Page Using a Command Component". Once that is done, you can set the parameter value for the form or table.

To create a form or table that uses parameters:

1. From the Data Control Palette, drag a collection that is a return of a method that takes a parameter or parameters and drop it as any type of form or table.

2. In the Edit Form Fields dialog or Edit Table Columns dialog, configure the form or table as needed and click OK.

   For help in using the dialogs, click Help.

   Because the method takes parameters, the Action Binding Editor opens, asking you to set the value of the parameters.

3. In the Action Binding Editor, enter the value for each parameter by clicking the ellipses (...) button in the Value field to open the EL Expression Builder. Select the node that represents the value for the parameter.

   For example, Example 10-5, "JSF Page Code for a Command Link Using a setActionListener Component" shows a `setActionListenerComponent` setting the `svrId` parameter value on the `userState` bean as the `currentSvrId` attribute. To access that value, you would use `#{userState.currentSvrId}` as the value for the parameter.

   This editor uses the value to create the `NamedData` element that will represent the parameter when the method is executed. Since you are dropping a collection that is a return of the method (unlike a method bound to a command button), this method will be run when the associated iterator is executed as the page is loaded. You want the parameter value to be set before the page is rendered. This means the `NamedData` element needs to get this value from wherever the sending page has set it.

## 10.6.2 What Happens When You Create a Form Using a Method that Takes Parameters

When you use a return of a method that takes parameters to create a form, JDeveloper:

- Creates an action binding for the method, a method iterator binding for the result of the method, and attribute bindings for each of the attributes of the object, or in the case of a table a table binding. It also creates `NamedData` elements for each parameter needed by the method.

- Inserts code in the JSF page for the form using ADF Faces components.

Example 10-11 shows the action method binding created when you dropped the `findServiceRequestsById(Integer)` method, where the value for the `findSvrId` was set to the `currentSvrId` attribute of the `UserState` managed bean.

Example 10-11 Method Action Binding for a Method Return

    <bindings>
      <methodAction id="findServiceHistoryById"
                    InstanceName="SRPublicFacade.dataProvider"
                    DataControl="SRPublicFacade"
                    MethodName="findServiceHistoryById" RequiresUpdateModel="true"
                    Action="999"
                    ReturnName="SRPublicFacade.methodResults.SRPublicFacade_
                                dataProvider_findServiceHistoryById_result">
        <NamedData NDName="svrIdParam" NDValue="${userState.currentSvrId}"
                   NDType="java.lang.Integer"/>
      </methodAction>
    ...
    </bindings>

Note that the `NamedData` element will evaluate to the current service request ID on the `userState` bean, as set by any requesting page.

## 10.6.3 What Happens at Runtime

Unlike a method executed when a user clicks a command button, a method used to create a form is executed as the page is loaded. When the method is executed in order to return the data for the page, the method evaluates the EL expression for the `NamedData` element and uses that value as its parameter. It is then able to return the correct data. If the method takes more than one parameter, each is evaluated in turn to set the parameters for the method.

For example, when the SREdit page loads, it takes the value of the `currentSvrId` field on the `userState` managed bean, and sets it as the value of the parameter needed by the `findServiceRequestsById(Integer)` method. Once that method executes, it returns only the record that matches the value of the parameter. Because you dropped the return of the method to create the form, that return is the service request that is displayed.