Oracle JDeveloper 10g Overview
Download
Report
Transcript Oracle JDeveloper 10g Overview
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
Design
Application
Modeling
Build
Test
Deploy
Data
Modeling
Coding
Tuning
Debugging
Deployment
Infrastructure
IDE
Platform
Configuration
Management
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
Controller
Struts
ADF Metadata Services
ADF Bindings
Model
ADF Data Control
Java
Classes
JDBC
EJB
Session
Beans
TopLink
Queries
Java Classes
ADF Business
Components
Service Object
EJB
Finders
EJB Entity Beans
TopLink Mapping
View
Web
Services
ADF Business
Components
Query Object
ADF Business
Components
Entity Object
Data
Access
Persistent
Business
Objects
Business
Services
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/
JSP
Servlet/
JSP
Servlet/
JSP
Web Server
Servlet/
JSP
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
HTTP
Response
Servlet
User
Actions
JSP
State Change
JavaBean
View
Selection
State Query
JDBC
Enterprise
JavaBean
Change
Notification
View
Model
DB
Database
Struts
Model-View-Controller ~ Model 2
Applying MVC to a Page Flow
Web
Server
Servlet/JSP Controller
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
Browser
App Server
Jsp 1
Jsp 2
Jsp 3
Form
Bean
1
JSP Engine
request/session
Form
Bean
2
View
Layer
Other
Bean
1
Controller
Strutsconfig.
xml
Mappings
•
path
• action
• [form bean]
• [forwards]
Action1
.java
Business
Bean 1
Action2
.java
Action3
.java
Business
Bean 2
JDBC
Database
Action4
.java
Business
Bean 3
Business
Logic
Layer
Data
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>
Jsp 1
Page 1
Web Browser
Jsp 22
Jsp
pure HTML sent to
browser
processes custom tags – fill form
elements from beans, display
internationalized messages request/session
Form
Jsp Engine
Form
Form
Bean
Application Server
incoming
requests
relevant page called
reads on
start-up
How it all Works
Jsp 3
Controller
1
if submit, auto any
creates/reuses
populates form
associated
form bean
bean
from request params
•• •
• • ••
Bean
Bean
2
View
Layer
looks up path to determine
creates
passes control
to relevant
returns
appropriate
action/ form bean
action to handle
forward
Strutsconfig.
xml
Mappings
•
•
•
•
path
action
[form bean]
[forwards]
Action2
Action2
.java
.java
Action1
.java
Action3
.java
interacts
lower (adds
layersto
- beans
gets
data with
to display
acts
as adaptor betweensaves
HTTPdata
in
request/session)…or
and layers
from
beansbelow
via business rules
Business
Bean 1
Business
Bean 2
Business Data
Business
Bean 3
Business
Logic
Layer
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