Anda di halaman 1dari 24

13

Creating Updatable Pages

Copyright © 2007, Oracle. All rights reserved.


Objectives

After completing this lesson, you should be able to do


the following:
• Use components that facilitate data entry
• Invoke method actions in the page definition
• Bind methods to buttons
• Use transactional methods:
– mergeEntity
– refreshEntity
– removeEntity
– persistEntity
• Call methods from a Managed Bean

13-2 Copyright © 2007, Oracle. All rights reserved.


Using Components That
Facilitate Data Entry

SelectOneChoice
component

SelectInputDate component

13-3 Copyright © 2007, Oracle. All rights reserved.


Using Methods on Pages

You can use methods to (for example):


• Decide navigational outcomes
• Pass parameters
• Execute business logic
• Perform Create-Retrieve-Update-Delete (CRUD)
transactions

13-4 Copyright © 2007, Oracle. All rights reserved.


Executing Methods in ADF

• Methods are defined in the page


definition file as operation
bindings.
• Operations can be accessed and
executed from ADF Faces.
• Enterprise JavaBeans (EJBs) use
methods on the ADF binding for
CRUD operations.

13-5 Copyright © 2007, Oracle. All rights reserved.


Executing Bound Methods
on JSF Page Load

• Actions in the
executable section
are invoked on page
load.
• Actions bind to
methods or actions
in the bindings
definition.
• Use Expression
Language to set
conditions that
determine when an
action is executed.
13-6 Copyright © 2007, Oracle. All rights reserved.
Constructors

Constructors:
• Are methods created as
part of the Data Control
• Are added to the
Constructors node
• Create a new object
• Can be used to build ADF
creation forms

13-7 Copyright © 2007, Oracle. All rights reserved.


Transactional Methods

The Session Facade includes the following methods


for transactions:
• mergeEntity
• persistEntity
• refreshEntity
• removeEntity

13-8 Copyright © 2007, Oracle. All rights reserved.


mergeEntity()

mergeEntity():
• Is added to the Session Facade Bean
• Is used for committing updates
• Checks for existence
• Merges transaction into unit of work
• Commits the transaction

13-9 Copyright © 2007, Oracle. All rights reserved.


persistEntity()

persistEntity():
• Is part of the Session Facade Bean
• Is used for inserts
• Checks for duplicates in unit of work
• Inserts an entity
• Commits the transaction

13-10 Copyright © 2007, Oracle. All rights reserved.


Using Transactional Methods

11

13-11 Copyright © 2007, Oracle. All rights reserved.


Building an Insert Form

• You use a default


constructor.
• JDeveloper builds an
ADF Creation Form.
• The constructor is called
when the page is loaded.
• The properties are
populated on submit.

13-12 Copyright © 2007, Oracle. All rights reserved.


Building an Insert Form

• Add the
persistEntity()
method.
• Add it as a button or
bind it to an existing
button.
• Pass the newly created
entity to the method.

13-13 Copyright © 2007, Oracle. All rights reserved.


Building an Insert Form

• Change the Action property to point to a


navigation case.
• Add a Cancel button.

13-14 Copyright © 2007, Oracle. All rights reserved.


Displaying the Results

• Navigate to the
calling page.
• Set Cache Results
to false on the
iterator.
• The queries are
reexecuted each
time the page is
reloaded.

13-15 Copyright © 2007, Oracle. All rights reserved.


Using Backing Beans

• Managed Beans can contain:


– Business logic
– Interaction with data sources
• Backing beans are a special type of Managed Bean
that:
– Interact with the User Interface (UI) components
and the model
– Are associated with UI components by using JSF
Expression Language
– Can contain event listener methods
– Contain getter and setter methods for UI
components

13-16 Copyright © 2007, Oracle. All rights reserved.


Backing Bean: Example

JDeveloper creates for each field:


• Properties
• get() and set() methods

13-17 Copyright © 2007, Oracle. All rights reserved.


Creating Backing Beans

• When you create a JSF


page, you can choose
to associate UI
components with a
Managed Bean.

• You manually create


Managed Beans by
associating class files
in the JSF
Configuration Editor.

13-18 Copyright © 2007, Oracle. All rights reserved.


Creating Backing Beans

You can automatically create a Managed Bean when


you create a page:
• Attribute and
getter or setter
methods for each
UI component
• Managed Bean
automatically
synchronized with
UI changes

13-19 Copyright © 2007, Oracle. All rights reserved.


Creating Managed Beans by Binding a
Command Button

You can also create a Managed Bean from the page:


1. Double-click the Command button.
2. Click New.
3. Name the bean and class.
4. Select the scope.
5. If the class does not exist, JDeveloper creates it.

13-20 Copyright © 2007, Oracle. All rights reserved.


ADF Binding

13-21 Copyright © 2007, Oracle. All rights reserved.


Configuring ADF Binding Access for
Managed Beans
• Create a managed property
and set its value to
#{bindings}.
• In the Managed Bean, create an
instance variable with the
same name as the
managed property.
• Make sure the variable type
is oracle.binding.BindingContainer.
• Create setter and getter methods for the instance
variable.
• The binding is automatically configured on
declarative method binding creation.

13-22 Copyright © 2007, Oracle. All rights reserved.


Summary

In this lesson, you should have learned how to:


• Use components that facilitate data entry
• Invoke method actions in the page definition
• Bind methods to buttons
• Create an Insert page
• Use transactional methods:
– mergeEntity
– refreshEntity
– removeEntity
– persistEntity
• Create and use Managed Beans

13-23 Copyright © 2007, Oracle. All rights reserved.


Practice Overview:
Completing the Edit Page

This practice covers the following topics:


• Creating a Query page
• Using a constructor for an Insert page
• Using persistEntity() to commit changes to the
database
• Adding components to the SREdit page to make it
more user-friendly
• Committing an update

13-24 Copyright © 2007, Oracle. All rights reserved.

Anda mungkin juga menyukai