+ All Categories
Home > Technology > Metamorphosis from Forms to Java: A technical lead's perspective, part II

Metamorphosis from Forms to Java: A technical lead's perspective, part II

Date post: 03-Sep-2014
Category:
Upload: michael-fons
View: 1,375 times
Download: 1 times
Share this document with a friend
Description:
JSF presentation I did for RMOUG, May 2007
Popular Tags:
47
Metamorphosis from Forms to Java: Part II Michael A. Fons RMOUG Quarterly Meeting May 2007
Transcript
Page 1: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Metamorphosis from Forms to Java: Part II

Michael A. Fons

RMOUG Quarterly Meeting

May 2007

Page 2: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Preamble

• Demo-Centric presentation• Walkthrough of ADF basics

– Deployment– Model side– Presentation layer– Binding– Beans– Scope– More…

Page 3: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Issues and Highlights

• What follows are technical issue and highlights of ADF and JDeveloper features.

• Main resources I used were – Oracle Application Development Framework Developer’s Guide

for Forms/4GL Developers – Oracle JDeveloper 10g for Forms & PL/SQL Developers: A

Guide to Web Development with Oracle ADF – Dive Into ADF Blog, AMIS website, Frank Nimphius…

• These two books cover this material in great detail. I recommend them both highly.

• JDeveloper allows access to many technology stacks; – I only cover one here. – These two books also cover this same stack I am covering.

(ADF BC, JSF)

Page 4: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

First Subject: Deployment• OC4J: learn about it; work with it.

– Great container! – Fully functional (and free). – Gives you deployment practice…

• OC4J will only take you so far: – need to deploy to real test bed (like Oracle 10g AS)– This will help you feel confident and remain motivated.– This laptop is has 1 Mb of RAM and runs (walks?)…

• OAS 10.1.3.1• JDeveloper 10.1.3.1• Oracle XE database 10g• Internet Explorer

– Better to have multi-tiered environment• You or your company may need to get some more hardware (used is OK); • deploying to existing servers can be too scary at first to inexperienced system

administrators.• Might consider virtual machine software (like VMWare or Xen)

• The paper which accompanies this presentation has instructions if you want to set up 10.1.3 OAS on a Red Hat install. This is pretty easy.

Page 5: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Deployment• If you are deploying to OC4J or

OAS you can deploy several ways:

– Developers using JDeveloper can create an application connection to deploy easily.

– Other deployment methods require an EAR file or something like it. To make an EAR file…

• create a WAR deployment profile in JDev (use New…on context menu for ViewController Resource Folder).

• In deployment profile context menu deploy to an EAR file.

– With an EAR file you can use…• Oracle Enterprise Manager to

deploy from anywhere.• admin.jar to deploy from the

server side.

Page 6: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Deployment

• Cautions:– OAS 9.0.4, 10.1.2 and 10.1.3 have different

deployment requirements partially because they run different versions of the JDK; so your deployment target matters when attempting a deployment.

– JDeveloper help has deployment instructions, which are somewhat helpful and somewhat erroneous depending on what version you are deploying to

– see paper for details on JDev 10.1.2 to OAS 9.0.4 errata.

– Save time: follow the Oracle compatibility matrix.

Page 7: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Demo 1: a deployment

• Deploy a simple application

• Run it on an external OC4J

Page 8: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

MVC (Model-view-controller)

• In a web program – the “view” is what you see and interact with. – the “model” is the data and the data access.– changing one can affect the other.

• MVC promotes having an intermediate layer called the “controller” layer to allow changes to view or model without affecting the other.

Page 9: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

MVC: the Model side

• ADF BC is what I have worked with on the model side. (I do not know TopLink, etc.)

• With ADF BC you use an Entity pointing to a database table if you want to update/insert/delete that table’s data.

• A View Object needed when you want to select.• Entities and View Objects can be linked together, like with tables

and their PK/FK’s, with Associations and Link Objects.• View Objects nest in Application Module objects (hence: the icon for

application module is a suitcase.) • Application modules should contain the data controls that represent

a Use Case or a “unit of work” (building blocks)

Page 10: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

MVC: the Model side

• Drag and drop on Business Component diagrams – may help visual-learners.

• Entities/Associations often come from tables/referential constraints. – Can drag

• entities into views to make a query/view based on a table/entity.

• views/view links into application modules to make instances of these objects.

• application modules into other application modules

• View Object control hints will allow you to more easily deploy your application to different locales (countries) with very few configuration changes.

Page 11: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Demo 2: create simple model

• Create new app

• Create new Entity from a table

• Create a new View to go with that Entity

• Create an Application Module to go with that View

Page 12: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

MVC: View/Controller• In JDev app templates, View and Controller

are bundled separate from Model, probably because Model objects are more likely to be shared between applications. All three parts of MVC are of equal importance, however.

• Controller: Oracle favors JSF over Struts because of

– wide acceptance and government by JCP (Java Community Process).

– Also JSF reacts at the component level, where Struts reacts at the page level.

– SUN may like Struts better• Faces-config.xml tracks…

– navigation rules • nice diagramming tool for this; called

navigation modeler/diagrammer• what beans/properties your application has

– lots of other stuff (see Overview tab)

Page 13: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Demo 3: add a simple UI

• Add a simple form page UI to the model we created.

Page 14: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Inter-page data passing

• Can use parameters for passing information.• Other data can be stored in request, session or process-scope

variables (more about them in a minute…).• Like passing data: If you use the same iterator crossing pages you

will not lose the current-row marker setting.• Can use Transient View Objects

Page 15: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Visual Designer

Page 16: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Visual Designer• Double-click a web page icon on

the Navigation Diagrammer or the Navigator pane to edit a page with the Visual Designer editor.

• Can drag individual GUI components or data-based data-control components and operations onto the page or structure pane.

• Can drag-and-drop, or select and click (for components).

Page 17: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Bindings• Can mean different things

depending on context (bind variables, data bindings)

• Very important to understand how to manually create and edit bindings (Koletzke).

• Bindings connect things: – GUI components to iterators,– GUI components to data elements,– GUI components to actions and

methods

• Right-click on your visual designer page and choose the Page Definition file to see your page’s bindings so far.

Page 18: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Bindings

• Another way to see bindings: in the visual designer you can click on and then right-click in a data field and choose Edit Bindings to open up the Attribute binding editor.

• To make your page to use custom model code you write you will need to do the following:– Commonly you would create or override a Java method in your

extended application module file.– Expose this method on the Client Interface Node of the App

Module editor. (Double-click the application module to enter this editor.)

– Insert a method binding into the page definition file structure pane.

– Now you can call your code from a button or an invokeAction executable.

Page 19: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Demo 4: take a look at visual designer and bindings

• Peruse visual designer of simple UI we just created

• Take a look at the bindings for this page

Page 20: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

New Subject: Beans

• What are beans? – reusable Java programs

• According to wikipedia.com, the required conventions of JavaBeans are…– The class should be serializable (able to persistently

save and restore its state) – no-argument constructor – have get/set “accessors” for each class attribute – It should contain any required event-handling

methods

Page 21: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Beans

• Where are beans found in ADF?• There appears to be both View-layer and

Model-layer beans in ADF apps.– GUI/Presentation layer validation– Storing inter-page persistent data.

Page 22: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Beans

• Model versus View beans– Model layer

• Model-level Java programs accessible within the Sources folder in the structure pane when the BC component is highlighted in the Application Navigator;

• java settings for this component must have java code option turned on.

• JDev documentation does not refer to these programs as beans.– View layer

• You can create/manage (View layer) managed beans through your configuration editor (faces-config.xml overview tab).

• Binding layer calls these beans.• It is possible to interact and manipulate binding through bean code.

(Koletzke: this is a really good thing to learn how to do.)

Page 23: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Beans

• Helpful facts about beans:– You can bind an input field on a page directly to a bean attribute.

Use the EL format “<beanname>.<attribute>” to reference it. (Note: “<scope>.<beanname>.<attribute>” may cause an error.)

– You can opt to have JDev automatically maintain backing beans so when you add a new attribute to a page the backing bean gets a corresponding attribute added. (You can also double-click on a GUI component and create a bean from there.)

– Can change name (id) property of your fields and beans by altering the id in your property sheet. This editing method allows you to have better names for your fields to references in your custom code later.

Page 24: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Demo 5: create backing bean for a couple of UI components

• Create bean for a field

• Create a button with a backing attribute in the same bean.

• Make the button programmatically change attributes on a field.

Page 25: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Scope

• like “automatic” beans…(not aeromatic).• Request, Process, Session, Application Scope variables

are created dynamically on reference to them.• Inter-page data storage

– If SetActionListener component is dropped onto a button, then it sets a value prior to executing the action associated with the button.

– I told the SetActionListener to do a (from, to) of (#{row}, #{processScope.detailContacts}). Then I made the target page reference #{processScope.detailContacts.Pid} as its value.

– The result was values were passed from page to page painlessly.

– Request or other scope works just as well for inter-page value passing.

Page 26: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Demo 6: pass some data

• Create a second page using a different view

• Pass some existing data from page one to page two using request scope

Page 27: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

GUI Components

• There are Model- and View-layer components.– Model

• View Objects, • Application Modules, • Entities

– View- or Presentation-layer (GUI) components• what you see (or not) on a web page like a

– button, – field, – drop-down list

• JSF and ADF Faces have many View-layer components to choose from.

Page 28: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

GUIComponents

• Form – vertical field layout• Table – horizontal, multi-row layout• Tree

– Tree binding editor– What data elements do you want to see on each level?– Link current rule to next (branch rule accessors)

• Adf Faces switcher and JSF facets – conditionally showing parts of your web page.

• Drop Collection-level action “executeWithParams” to get ADF Parameter Form

• So many more…

Page 29: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Demo 7: GUI component palette

• Create a page which uses a find window for parameter value.

• Make this page use a switcher component.

Page 30: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Collection vs. Iterator• Initially it was difficult for me to understand

what a collection was and what an iterator was.

• Model layer has Application Modules and View Object instances inside of it. ViewController layer has DataControl with Collections inside of it. App Module and DataControl are two ways of looking at the nearly the same thing – depending on what layer you are in.

• Iterators are like cursor pointers in pl/sql; they point at a particular row in a returned set of data rows (a collection…which is a rowset inside a view object instance).

Page 31: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Oddballs and Whiney-bits

• While learning and experimenting I ran into things that threw me for a loop.

• The following section will help you be prepared for these same stumbling blocks, hopefully.

• Many other gotchas are highlighted in the ADF Developer’s Guide.

• New versions of JDev will makes these disappear and others appear, no doubt.

Page 32: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Odd-balls…

• If you move your JDev home…– any applications that you have run against JDev’s

embedded OC4J server has imiplicitly been deployed there, and would need to be un-deployed and redeployed to make this move successful.

– No EM on this server instance so you would probably need to use admin.jar to do this.

– It is probably easier to just reinstall JDev to the new location and open your application in the new JDev.

Page 33: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Oddballs…

• Your pages, iterators and fields on your page can be granted access to roles through Authorization Editor.

• Authorization Editor hard to find. – open the page definition for the page in question. – click on the page definition page, – go to the structure window– right click on the Page Def (root) node in that structure window. – select the option to “Edit Authorization”

• Other security settings occur in web.xml and in the embedded OC4J settings. Also jazn.xml

Page 34: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Demo 8: use the authorization editor to make some components

read-only

• Run a simple log-in application; demonstrate access on a particular field

• Open authorization editor; alter permission for a that field

• Re-run with same log-in; show access has changed.

Page 35: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Oddballs…• Entity Definitions are to Entities as View Objects

are to ViewRow Objects. Why not View Def/View Row, or Entity Object/EntityRow?

• Creating custom properties in AppModules, View Objects or Entities is possible…but is annoying.

• If you normally set proxy exceptions in your intranet may need to set Embedded OC4J Server Preferences Startup to use localhost instead of your machine name.

• Deleting and re-adding things to Data Model diagrams can create really long link lines.

Page 36: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Oddballs…• Make view objects that are

based on multiple entities able to update all its entities with the click of a checkbox (might need some additional programming, too).

• ADF manual for Forms/4GL Developers, Chapter 9 has some typos and omissions that are handy to know about – see the paper.

• If computer is forcibly rebooted while you have changes to save it can mess up your JDev installation; so can certain mistaken uses of JDev functionality. (need reinstall)

Page 37: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Demo 9: multi-table updatable view

• Create a view to select from multiple tables.

• Make both tables updatable.

• Run application. Demonstrate update of both tables.

Page 38: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Oddballs…

• On a Form component, if you use bindings EL expression to keep a record counter against an iterator (to create “page 3 of 10” and the like) and the iterator’s RangeStart expression does not seem to be advancing, …– make sure that the page definition file’s setting of

RangeSize is set to the number of rows displayed on the screen (i.e., 1 for a Form).

– The default for this attribute for iterators is 10. – It should instead match the number of records you

are displaying on that page (1 for a form component).

Page 39: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Oddballs…

• The ADF Developer’s Guide says Table components will not allow you to bind a database table to a list element within it. – But I tried it, and it worked fine.

• Watch out for java.lang.Number versus oracle.jbo.domain.Number ; datatype mismatch errors involving numbers are probably caused by these.

Page 40: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Demo 10: create list element in a table component

• Create a page with a drop-down list based on a view.

Page 41: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

A Word about JHeadstart

• Good productivity tool• Consistant UI• Costs extra• JHeadstart authors not so emphatic about 100%

generation as in Headstart product.• Will factor in Designer repository modules.• You would have to learn yet another

“declarative” layer though…• May help Designer users migrate to ADF

Page 42: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Some Tips…

• I have a few things left to say which will help someone out there…

• Then we are done.

Page 43: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Tips

• Good things to remember about ADF…– As you are building your page, drag items from the Data Control

palette rather than the Component Palette when possible.– Learn names of different components, editors, panes/panels,

etc. This will help in reading documentation.– Refactoring: a year ago refactoring was not safe. Now it is. Go

for it. Only a few thing need doing manually (e.g., change DataBinding.cpx if you change the name of a page).

Page 44: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Tips

• Your application module has a “main” method in it if you need to run your model in debug mode. It works great!

• If you publish your custom method in the client interface you may need to rebuild your client interface code so that “code insight” in your code editors shows your new code changes.

• SRDemo great to study. Oracle ADF Guide for Forms/4GL Developer’s works with this app in code examples.

Page 45: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Final Tips…

• The application module’s constructor does not represent the start of the life of the application module. Instead, override “create” method if you want to do something which coincides with the beginning of the App Module’s life.

• Try to create your Framework Extension Layer as soon as you can stomach it– check out chapter 25.1 through 25.3 in Developer’s

Guide to do so. – This will give you flexibility in the long run.

Page 46: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Demo 11: extend your framework to use pl/sql

• Add a framework extension to an application.

• Add a call to a use of pl/sql that occurs in the framework.

• Run the application.

Page 47: Metamorphosis from Forms to Java:  A technical lead's perspective, part II

Any Questions?

• Hope you enjoyed this presentation.

• Any questions? Special requests?

• Contact me at [email protected]


Recommended