jdeveloper 10g web development with adf and struts

Upload: claudioftr

Post on 06-Apr-2018

233 views

Category:

Documents


1 download

TRANSCRIPT

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    1/55

    1

    JDeveloper 10g Web Application

    Development with ADF and Struts

    By Shaun D. OBrien, TUSC

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    2/55

    2

    Abstract

    JDeveloper 10g is an amazing developmentenvironment. With the Oracle Application DeveloperFramework (ADF), which includes TopLink, BC4Jand Struts, you can quickly and easily develop a

    GUI/HTML-based Web application using this point-and-click, drag-and-drop development tool. Thispresentation will discuss: How ADF allows you to map a database object into an

    ADF Business Component

    ADF Business Component view objects

    ADF Business Component Application Modules

    The ADF Data Bindings and Control components

    The Struts Controller

    The Java Server Page

    In one hour you'll learn how to quickly develop anapplication using JDeveloper 10g

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    3/55

    3

    Topics Covered - Agenda

    What is JDeveloper?

    What is ADF?

    What is Struts?

    Quick Web Development

    Tips and Tricks

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    4/55

    4

    What is JDeveloper 10g?

    Oracle JDeveloper 10g is a J2EEdevelopment environment with end-to-endsupport for modeling, developing,

    debugging, and deploying e-businessapplications and Web services. OracleJDeveloper 10g allows developers to buildJ2EE applications and Web services eitherfrom scratch or by using a J2EE

    framework. Whatever implementation ischosen, JDeveloper offers all theproductivity tools needed to get the jobdone.

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    5/55

    5

    New Features as of 10g

    Application

    Development

    Framework (ADF) Faster Development

    Integrated MVC

    patterns

    New J2EE Features

    New wizards TopLink integration

    Web Service

    improvements

    IDEEnhancements

    New look and feel

    Code editorimprovements

    Better modeling

    Database

    Development

    Database modeling Editing DB objects

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    6/55

    6

    What is ADF?

    Oracle ADF is a comprehensiveproductivity layer for J2EEdevelopers. It simplifiesbuilding applications as a set of

    business services with Web,Wireless, and Rich Clientinterfaces. ADF acceleratesdevelopment with ready-to-useJ2EE Design Pattern

    implementations and metadata-driven components that you'dotherwise have to code, test,and debug by hand.

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    7/55

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    8/55

    8

    What is Struts?

    The core of the Struts framework

    is a flexible control layer based on

    standard technologies like Java

    Servlets, JavaBeans,

    ResourceBundles, and XML, as well

    as various Jakarta Commons

    packages. Struts encourages

    application architectures based on

    the Model 2 approach, a variation ofthe classic Model-View-Controller

    (MVC) design paradigm.

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    9/55

    9

    Put Simply

    Struts provides the controller component

    and default request dispatcher for your

    web application. In addition, it providescomponents that can be utilized by a struts

    enabled application to manage integration

    with data access and delivery to the

    presentation layer.

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    10/55

    10

    Quick Web Development

    From table to

    HTML with

    navigation in no

    time

    Full MVC / Struts

    implementation

    Model Businesscomponents

    View JSP

    Controller -

    Struts

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    11/55

    11

    8 Steps to Success

    Create a 1 - New Workspace

    2 - Model (Business

    Components) Diagram 3 - Persistent Business

    Object

    4 - View Object

    5 - Application Module

    Controller

    6 - Create a Page Flow

    View

    7- Create a JSP Page

    8 - Run the Application

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    12/55

    12

    Create a New WorkspaceStep 1

    Right click on Applications in

    Navigator

    Click on New ApplicationWorkspace

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    13/55

    13

    Name the Workspace

    Name the

    workspace

    whatever you wish

    Use the default

    application

    template (Web

    application)

    Click OK

    Application

    workspace is then

    created

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    14/55

    14

    Model and ViewController

    2 new projects

    are

    automaticallycreated under

    the application

    Model

    ViewController

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    15/55

    15

    Create a Diagram of Business

    ComponentsStep 2

    Right click on

    Model

    Click New

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    16/55

    16

    New Business Components

    Diagram

    From the

    gallery,

    choose Business

    Components

    under

    Category Business

    Components

    Diagram

    Click OK

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    17/55

    17

    Name Your Diagram

    Name your

    Business

    Components

    Diagram as you

    wish

    Youre now finished

    setting up your

    environment

    Its time to build

    your application

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    18/55

    18

    Create a Persistent Business ObjectStep 3

    These are entity

    objects

    Implement the Data

    Access Object designpattern

    Responsible for

    persisting, caching and

    validating data

    Created by dragging atable object and

    dropping in the

    diagram

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    19/55

    19

    Connecting to the DB

    First you must be

    able to connect to

    the database

    In Navigator

    Select

    Connections at

    the bottom tab

    Right click onDatabase

    Select New

    Database

    Connection

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    20/55

    20

    Database Connection Wizard

    4 Steps

    Name the connection

    Specify a username and

    password to connect to

    Specify the connection

    parameters (i.e. the

    database and machine

    to connect to)

    Test the Connection

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    21/55

    21

    Drag and Drop the Table

    In the Navigator,

    drill into the

    newconnections

    tables

    Drag and drop a

    table into theBusiness

    Components

    Diagram

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    22/55

    22

    Editing the Object

    You can edit thePersistent BusinessObject by double-clicking it

    Edit, add or delete

    attributes Turn on batch updates

    Establish validationand authenticationrules

    Publish and subscribeevents

    This is a BC4J orEJBobject thatencapsulates all of thebusiness rules for the

    object

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    23/55

    23

    Referential Integrity

    If you add

    objects that

    have referentialintegrity

    established,

    JDeveloper

    automaticallypicks up on

    these

    relationships

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    24/55

    24

    Create a View ObjectStep 4

    This object gathers

    and filters the data

    stored in the entity

    object

    Uses a SQL Query

    to form a collection

    of data

    Can be comprisedof multiple entity

    objects (i.e. join

    tables)

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    25/55

    25

    Create the View Object

    In Business

    Components

    Diagram

    Click ViewObject

    Click in Business

    Components to

    place

    Name the view

    (i.e. EmpView)

    Have an empty

    view (i.e. no

    entities to pull yet)

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    26/55

    26

    Place the Entity Objects

    Drag and drop the

    Entity Object(s) (i.e.

    Emp and Dept) into the

    View Object (i.e.EmpView)

    Creates a 1:1 mapping

    from the entity object

    by default (i.e. all

    columns, all rows)

    Adding related tables

    will automatically

    create the join

    statement

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    27/55

    27

    Editing the View Object

    You can edit the viewobject

    Add additional entity

    objects into the view(or use the drag anddrop)

    Add or removeattributes from theentities selected

    Edit the query(manually), add awhere and/or order byclause

    Set fetch sizes, queryhints, etc.

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    28/55

    28

    Create an Application ModuleStep 5

    The Application

    Module is a

    service objectthat coordinates

    view objects for

    a specific task

    (i.e. a form todisplay the

    employee data)

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    29/55

    29

    Building the Application

    Module

    In BusinessComponents Diagram

    Click ApplicationModule

    Click in BusinessComponents to place

    Name the module (i.e.EmpModule)

    Have an empty module(i.e. no views to pullyet)

    Drag and drop the view(i.e. EmpView) into theModule

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    30/55

    30

    Editing the Application Module

    You can edit the

    attributes of the

    application module

    by double-clicking

    it, just like the

    other objects

    These objects can

    be deployed asEJB, Corba, or Web

    Service objects

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    31/55

    31

    JDeveloper Wizard

    The Quickmethod / wizardcan be used to

    create the Viewand Applicationobjects

    Right-click onEntity Object

    Select Generate,then

    Generate defaultData ModelComponents

    Skips Steps 4

    and 5!!!

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    32/55

    32

    Business Services are

    Complete

    All of ourbusinesscomponents

    have now beencreatedEntity Object

    View Object

    ApplicationModule

    Its time tocreate the GUI

    application

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    33/55

    33

    Diagram a Page Flow (Controller)Step 6

    This is our

    ViewController

    section of the MVC

    The controller (i.e.

    Struts) separates

    the visual

    representation of

    web pages (view)from their flow and

    actions

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    34/55

    34

    Creating the Forward Action

    Double-clickstruts-config.xmlin the navigator

    Then click Page

    Forward in theComponentPalette

    Then click in theStrutsPageFlowwindow to placethe Page

    Change the namefrom Page1(dont remove theforward slash)

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    35/55

    35

    Designing the JSP Page ViewStep 7

    Create JSP page

    that

    automaticallybinds to a Struts

    action

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    36/55

    36

    Creating the Page

    Double-click the

    Struts/forward

    action icon onthe page flow

    diagram

    Name the Java

    Server Page(JSP)

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    37/55

    37

    Dropping Business

    Components

    Utilizing the businessservice you created in themodel, well create the JSP

    In the Data ControlPalette, select the viewobject (i.e. EmpView)

    Select how you wish to dropthe object into the page (i.e.HTML table, Dynamic Table,Input Form, Read-only form,Graph, etc.)

    Drag and drop it onto thepage

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    38/55

    38

    The Default JSP Page

    By dragging and

    dropping the

    EmpView object as

    an Input Form

    each column from

    the table(s) is

    displayed

    Note that nonavigation buttons

    exist (only submit)

    by default

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    39/55

    39

    Adding Navigation

    In the Data Control

    Palette, under the

    view and underOperations you

    will find navigation

    operations.

    These can bedragged and

    dropped onto the

    page

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    40/55

    40

    Running the ApplicationStep 8

    Back to the

    StrutsPageFlow

    diagram

    Notice that the

    DataAction

    element was added

    Right-click on the

    DataActionelement and

    choose Run

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    41/55

    41

    The Application

    The form is

    complete and

    fully functional!!!

    Insert, update,delete, query

    HTML-based

    Easy to deploy

    using the one-click

    deployment

    How easy is

    that?

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    42/55

    42

    Adding a List of Values

    Delete theDeptNo inputfield

    Find the DeptNoin the DataControl Palette

    Select Drop AsList of Values

    Drop field inform

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    43/55

    43

    Associate LOV

    Need to

    Associate LOV

    to this field Will receive a

    strange BEAN

    error message if

    you dont Select the UI

    model icon

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    44/55

    44

    Create the LOV

    Edit the UI Models

    DeptNo object

    Create the LOV Choose the LOVsource (DeptView)

    Choose the Target

    (EmpView)

    Click Add Associate DeptNo

    to DeptNo for join

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    45/55

    45

    Display Attributes

    Choose your

    LOV display

    attributes Whatever fields

    you want to

    show in the LOV

    dropdown list

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    46/55

    46

    Try it Again

    More

    functionality

    exists now Also deleted

    EmpNo field and

    dropped as a

    value (ratherthan an input

    value)

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    47/55

    47

    Adding Additional Pages

    Is EASY!

    Add a new page

    forward to the

    struts-configdiagram and name

    it.

    Link emp action to

    our new action

    with a forwardlink, naming the

    forward with the

    event we wish to

    use.

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    48/55

    48

    Create Page

    Follow the same

    steps as before to

    create the page

    dragging DeptView

    as our data object.

    This time lets

    create it as a read

    only table forsimple display

    purposes.

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    49/55

    49

    Edit the Emp jsp

    Drag a submit

    button to the page

    from the component

    palette. Finally edit the

    buttons properties

    to set the name

    equal to the event

    we set in our struts-

    config diagram

    prefixing the event

    with event_

    (event_listall).

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    50/55

    50

    Try it out!

    Run the emp jsp

    again, this time

    click on our new

    button and you

    will navigate to

    the newly

    created

    summary page!

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    51/55

    51

    Tips and Tricks and Pitfalls

    http://otn.oracle.com/products/jdev/howtos/content.html

    Create aWorkspace foreach application

    Create a project foreach piece ofapplication

    Set up anindependentApplication Server

    Putting too muchsource in JSP isdangerous/bad

    Jdeveloper Log4J (Log for

    Java) JakartaProject

    Error Messages notalways clear, butthey are gettingbetter with eachrelease

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    52/55

    52

    Conclusion

    Powerful product!

    Some great newfeatures

    Enhancements tovisual creating andediting

    ApplicationDeveloper

    Framework is key Decreases

    development time

    Reduced learning

    curve

    Passionate

    about theTechnology

    Best in

    the World

    Economic

    engine

    Oracle

    TUSCs Vision

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    53/55

    53

    Questions and Answers

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    54/55

    54

    [email protected]

    metalink.oracle.com

    technet.oracle.com otn.oracle.com

    jakarta.apache.org

    www.tusc.com

    JDeveloper Help Tutorials are great

    Where to Get More

    Information

  • 8/3/2019 JDeveloper 10g Web Development With ADF and Struts

    55/55

    55

    Bradley D. Brown for his guidance and

    head start on this presentation.

    Please report errors to TUSC. NeitherTUSC, or the author warrant that this

    document is error-free.

    TUSC 2004. This document may not be

    copied or reproduced without theexpress written consent of TUSC.

    Special Thanks To