Docstoc

Oracle JDeveloper 10g Overview

Document Sample
Oracle JDeveloper 10g Overview Powered By Docstoc
					        Web Development with




Karsten Schulz Terp-Nielsen
Master Principal Sales Consultant
Oracle Denmark
Agenda

 JDeveloper 10g overview
 Application Developer Framework (ADF)
 Web Development with Struts
Full Lifecycle Support

          Application      Data
 Design                              Infrastructure
           Modeling       Modeling

                                         IDE
 Build               Coding            Platform



 Test       Tuning       Debugging
                                     Configuration
                                     Management

 Deploy         Deployment
JDeveloper Framework Support

 J2EE Frameworks
   –   Application Development Framework (ADF)
   –   Apache Struts support
   –   ADF Business Components
   –   Oracle 9i/AS10g Toplink
   –   UiX
   –   Java Server Faces (JSF)
Oracle ADF
End-to-end J2EE Framework
 Implements standard J2EE best practices
 Model-View-Controller (MVC) design pattern

            Rich Clients              Web and Wireless Clients


                                               Controller


                                Model


                           Business Services



 Focus on the application, not the “plumbing”
 Consolidation and evolution of previous frameworks
ADF – Productivity With Choice
                         Rich Client                                Web / Wireless
                          Swing / JClient                   JSP         ADF UIX        JSF             View

                                                                             Struts                  Controller

                                                   ADF Bindings
                                                                                                      Model
                                                 ADF Data Control
 ADF Metadata Services




                          Java
                                         EJB            ADF Business                Web
                                                                                                     Business
                                       Session           Components
                         Classes
                                        Beans           Service Object
                                                                                  Services           Services

                                                                  ADF Business
                                    TopLink         EJB                                   Data
                          JDBC                                    Components
                                    Queries       Finders                                Access
                                                                  Query Object



                                                                     ADF Business       Persistent
                           Java Classes       EJB Entity Beans                          Business
                                                                     Components
                                    TopLink Mapping                  Entity Object       Objects
Struts
Model 1 Architecture


 Browser access JSP pages – JSPs access
  JavaBeans that represent model
 Control de-centralized – current page display,
  determined next page to display
 Complex navigation requires use of scriplet code
     –   Blurs the line between presentation and navigation code
         and making reuse difficult
 Not a model to use in practice - maintenance
  difficult and does not scale well
Struts
Model 1 Architecture
                                                Model 1




  Decentralized controller - in each JSP page
Struts
Model 1 Architecture

No MVC - Statically Linked Pages




      Servlet/         Servlet/     Servlet/   Servlet/
       JSP              JSP          JSP        JSP

                            Web Server
Struts
Model-View-Controller ~ Model 2

   Introduces a controller servlet
      –   Controller Servlet handle the data access and
          navigational flow
      –   JSPs handle presentation

   Controller centralizes the logic for dispatching
    requests to the next view based on the request
    URL, input parameters, and application state

   Controller also handles view selection, which
    decouples JSP pages and servlets from one
    another
   Struts
   Model-View-Controller ~ Model 2


                     Controller
           HTTP
           Request                    State Change   JavaBean
                       Servlet

                  User    View                                             DB
                                                                  JDBC   Database
HTTP            Actions   Selection
Response                                             Enterprise
                                   State Query
              JSP                                    JavaBean
                                   Change
                                 Notification

                View
                                                       Model
       Struts
       Model-View-Controller ~ Model 2
Applying MVC to a Page Flow




  Web
                              Servlet/JSP Controller
  Server
Struts
What is It ?


 Open source Apache Jakarta Project
 An implementation of MVC paradigm
 A framework written in Java, to build web tier
  employing servlets, JSPs and XML
 De facto standard for J2EE MVC applications
 Bundled with JDeveloper and works on OC4J
Struts
Components

 ActionServlet class – Part of controller that receives
  user input and state changes and issues view
  selections
 Action class – Part of controller that interacts with
  model to execute a state change or query
 ActionForm Beans – Data (from Form) bundled into
  Javabean for reuse and perform validation
 ActionForward class – stores path to a page where the
  user is sent to
 ActionMapping – holds mapping that tells controller
  which Actions, ActionForms, ActionsForwards to use
Struts
Components (2)


 Struts-config.xml – Glue of the framework - holds
  declarations of the earlier listed components and
  other details. ActionServlets reads this file and create
  the configuration objects in memory
 Strut Tag Libraries – Custom tags that simplify
  working with Struts aiding the view component and
  access Model thru’ Java Beans
 Property files – store messages and handle different
  languages
Struts
Struts Pictorially

      Page 1
                 Web           Jsp 1       Jsp 2      Jsp 3
               Browser

App Server                                                                   Form   request/session    View
                                       JSP Engine                            Bean   Form               Layer
                                                                               1    Bean    Other
                                                                                      2     Bean
                                                                                              1


                    Controller
   Struts-
   config.
    xml
               Mappings

               •  path                 Action1          Action2          Action3           Action4
               • action                 .java            .java            .java             .java
               • [form bean]
               • [forwards]

                                                                                                      Business
                                           Business               Business          Business
                                                                                                       Logic
                                            Bean 1                 Bean 2            Bean 3
                                                                                                       Layer
                                                              JDBC
                                                                                                      Data
                                                              Database                                Layer
Struts
ActionForm


 Holds state and behavior for user input
 ActionForms are JavaBeans with reset() and
  validate() methods for user input
 ActionForm extends
  org.apache.struts.action.ActionForm
 Typically one ActionForm bean created for each
  HTML form
 ActionForm has corresponding property for each field
  on HTML form
Struts
ActionForm Example
public final class FAQForm extends ActionForm {
    private String question;
    private String answer;
    ..
    public String getQuestion(){
    return question;
  }
    public void setQuestion(String question) {
    this.question = question;
  }
   ..
    public ActionErrors validate(ActionMapping mapping,
                            HttpServletRequest request) {
    ActionErrors errors = new ActionErrors();
    if ((getQuestion() == null) || (getQuestion().length() < 1))
    errors.add("question",
                   new ActionError("errors.question.required"));
    ..
    return errors;
    }
}

<!-- Logon form bean definition in struts-config.xml -->
<form-bean name="FAQForm" type="faqapp.web.struts.forms.FAQForm" />
Struts
Action


 Action class receives the ActionForm(which
  holds the data) and you perform
  action/processing here
 Action provides a loose coupling between
  Web tier and business tier
 Controller decides which Action class, using
  the mapping info
 Action is invoked by calling perform() method
   Struts
   Action - Example

public final class FAQQueryAction extends Action {
   public ActionForward perform(ActionMapping mapping,
                                  ActionForm form,
                                  HttpServletRequest request,
                                  HttpServletResponse response)
        throws IOException, ServletException {
         String result = null;
         ...
         try {
           result = FAQHelper.getFAQHelper().query(actionForm, request);
           request.setAttribute("action", Constants.QUERY);
         }
         ...
       return mapping.findForward(“result”);
     }
}
Struts
ActionMapping

 ActionMapping object maps the Actions to
  URI, or path
 Specified in struts-config.xml
  <action-mappings>
     <action
       path="/faqQuery"
       type="faqapp.web.struts.actions.FAQQueryAction"
       name="FAQQueryForm"
       scope="request"
       validate="true"
       input="/faqQuery.do">
  </action-mappings>
Struts
ActionForward

 Encapsulates the destination of where to send control
  upon completion of the Action
 The destination(JSP, HTML file , servlet) is detailed in
  the configuration file – struts-config.xml
 Objects that have logical name for referring and a
  path property

   <! -- Forward Definition in struts-config.xml     -->
   <forward
     name="success"
     path="/WEB-INF/FAQQuery.jsp"/>
Struts
ActionServlet


 Primary task is to route request URI to an Action class
  using the configuration information(struts-config.xml)
 Is the director - working behind the scene,
  administering the behavior of controller
 Configured using web.xml of the application and
  mapped to receive url patterns such as *.do
 Only one ActionServlet can be loaded for an
  application
 Used as a black box in most cases, though it can be
  extended
Struts
struts-config.xml


 Holds declarations of Struts components that define
  the configuration
 Living blueprint of your application
     –   What fields are on the forms
     –   Where JSPs are found
     –   Knows about every action and the resources needed
 Power and flexibility of Struts is due to extracting out
  configuration information, across the frame work into
  struts-config.xml
  Struts
  struts-config.xml - Example
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.0//EN”
"http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
<struts-config>
  <!-- ========== Form Bean Definitions ========================= -->
  <!-- FAQForm form bean -->
  <form-bean name="FAQForm" type="faqapp.web.struts.forms.FAQForm“/>
 <form-bean name="FAQQueryForm“
                    type="faqapp.web.struts.forms.FAQQueryForm" />
<!-- ========== Global Forward Definitions ================ -->
  <global-forwards type="org.apache.struts.action.ActionForward">
  <forward name="error" path= “ /WEB-INF/Error.jsp" />
  <forward name="warning" path= “ /WEB-INF/Warning.jsp" />
  </global-forwards>
  <!-- ========== Action Mapping Definitions =================== -->
  <action-mappings>
  <action path="/faqQuery"
   type="faqapp.web.struts.actions.FAQQueryAction" name="FAQQueryForm"
   scope="request" validate="true" input="/faqQuery.do">
</action-mappings>
</struts-config>
  Struts
  A Look into web.xml
<servlet>
  <servlet-name>action</servlet-name>
  <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
  <init-param>
    <param-name>application</param-name>
    <param- value>ApplicationResources</param-value>
  </init-param>
  <init-param>
     <param-name>config</param-name>
     <param-value>/WEB-INF/struts-config.xml</param-value>
  </init-param>
  <init-param>
     <param-name>debug</param-name>
     <param-value>2</param-value>
  </init-param>
  <init-param>
      <param-name>detail</param-name>
      <param-value>2</param-value>
  </init-param>
</servlet>
       Page 1                     Jsp 1       Jsp 2
                                              Jsp 2       Jsp 3                       How it all Works
              Web Browser                       pure HTML sent to
                                                browser
                                                      processes custom tags – fill form
Application Server                                    elements from beans, display
                                                      internationalized messages request/session
     incoming                                                             Form                         View
                                          Jsp Engine                      Bean  Form
                                                                                 Form
     requests                                                                                          Layer
                                                                                  1        Bean
                                                                                           Bean
                                                                                  •• •
                 relevant page called                                                       2
                                                       if submit, auto
                                                      creates/reuses any          • • ••
  reads on
                                                       populates form bean
                                                      associated form bean
  start-up            Controller                       from request params
    Struts-           looks up
                      creates path to determine
    config.                          passes appropriate
                                     returns control to relevant
                      action/ form bean
     xml
                                     action to
                                     forward handle
                Mappings

                •   path                  Action1           Action2
                                                            Action2          Action3
                •   action                 .java             .java
                                                              .java           .java
                •   [form bean]
                •   [forwards]                         interacts to display layers -
                                                       gets data with lower (adds to beans
                                                       acts as adaptor between HTTP
                                                       in request/session)…or saves data
                                                       fromlayers below
                                                       and beans via business rules                   Business
                                              Business                Business             Business    Logic
                                               Bean 1                  Bean 2               Bean 3     Layer


                                                                                                      Data
                                                                  Business Data                       Layer
Struts
JSP Tag Libraries
 HTML JSP custom tags
     –   bridge between a JSP view and the other components of a
         Web application
     –   Tags relating to HTML forms, message and error handling,
         maintaining hyperlinks and internalization
 Bean JSP custom tags
     –   Tags useful for accessing beans, their properties,and
         defining beans based on access
     –   Create new beans based on the value of request cookies,
         headers, and parameters in any scope
 Logic tags
     –    Tags for conditional generation of output text, looping,
         comparison/sub-string matching
Struts
Using Struts JSP tags
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<HTML>
<HEAD>
<TITLE>Welcome!</TITLE>
<html:base/>
</HEAD>
<BODY>
<logic:present name="user">
<H3>Welcome <bean:write name="user" property="username"/>!</H3>
</logic:present>
<logic:notPresent scope="session" name="user">
<H3>Welcome World!</H3>
</logic:notPresent>
<html:errors/>
<UL>
<LI><html:link forward="logon">Sign in</html:link></LI>
<logic:present name="user">
<LI><html:link forward="logoff">Sign out</html:link></LI>
</logic:present>
</UL>
<IMG src='struts-power.gif' alt='Powered by Struts'>
</BODY>
</HTML>
Demonstration



Develop a Web Application based on Struts and
             EJBs as the model

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:22
posted:8/29/2012
language:English
pages:31