Oracle® Application Development Framework Developer's Guide
10g Release 3 (10.1.3) B25386-01 |
|
![]() Previous |
![]() Next |
There may be cases where an action on one page needs to set the parameters for a method used to display data on another page. As Figure 10-5 shows, the SRList page in the SRDemo application uses command links, which the user can click in order to directly edit a service request.
The commandLink
component is used to both navigate to the SREdit page and to set the needed parameter for the findServiceRequestById(Integer)
method used to create the form that displays the data on the SREdit page. You can use the ADF Faces setActionListener
component to set parameters.
Tip: The SRDemo application does not use thesetActionListener component for this page. Instead, this same functionality is provided by methods on a managed bean, as more than one page needs the same logic to set this parameter for the SREdit page. When logic needed for one page is also needed by other pages, it might be beneficial to place that logic on a managed bean. For more information about using managed beans, see Section 10.2, "Using a Managed Bean to Store Information".
|
You can use the setActionListener
component as a child to any command component.
To use the setActionListener component:
Create a command component using either the Data Control Palette or the Component Palette.
From the Component Palette, drag a setActionListener
component and drop it as a child to the command component.
In the Insert ActionListener dialog, set From to be the parameter value to pass to the method for the next page.
Set To to be where you want to set the parameter value for use by the method for the next page.
Tip: Consider storing the parameter value on a managed bean or in scope instead of setting it directly on the resulting page's page definition file. By setting it directly on the next page, you lose the ability to easily change navigation in the future. For more information, see Section 10.2, "Using a Managed Bean to Store Information". Additionally, the data in a binding container is valid only during the request in which the container was prepared. Therefore, the data may change between the time you set it and the time the next page is rendered |
Set the navigation for the component using the Action
attribute. For more information, see Chapter 9, "Adding Page Navigation Using Outcomes"
When you create the form (or other widget) for the next page using the method that takes the parameter, set the parameter to the value of the To attribute in step 4. For more information, see Section 10.6, "Creating a Form or Table Using a Method that Takes Parameters".
The setActionListener
component lets the command component set a value before navigating. When you set the From
attribute to the source of the value you need to pass, the component will be able to access that value. When you set the To
attribute to a target, the command component is able to set the value on the target. Example 10-5 shows the code on the JSF page for a command link that accesses the data for the current row as the from
value and sets that as the value of an attribute on a managed bean using the To
attribute.
Example 10-5 JSF Page Code for a Command Link Using a setActionListener Component
<af:commandLink actionListener="#{bindings.setCurrentRowWithKey.execute}" action="edit" text="#{row.svrId}" disabled="#{!bindings.setCurrentRowWithKey.enabled}" id="commandLink1"> <af:setActionListener from="#{row.svrId}" to="#{userState.currentSvrId}"/> </af:commandLink>
When a user clicks the command link, before navigation occurs, the setActionListener
component sets the parameter value. In Example 10-5, the setActionListener
gets the current row's svrId
attribute value and sets it as the value for the currentSvrId
attribute on the userState
managed bean. Now, any method that needs this page's current row's svrId
can access it using the EL expression #{userState.currentSvrId}
.
For example, when dropping the findServiceRequestById(Integer)
method to create the form for the SREdit page, you would enter #{userState.currentSvrId}
as the value for the Integer
parameter. For more information, see Section 10.6, "Creating a Form or Table Using a Method that Takes Parameters".