dr. paul dorsey dulcian, inc. - new york oracle user group · (basic adf element) frequently used...

44
Struts Development Dr. Paul Dorsey Dulcian, Inc. New York Metro Area Oracle User Group Day September 21, 2004

Upload: others

Post on 11-Jun-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Struts Development

Dr. Paul DorseyDulcian, Inc.

New York Metro Area Oracle User Group DaySeptember 21, 2004

Page 2: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Agenda

OverviewStruts elementsJDeveloper implementation of StrutsCreating Struts-based applications

Page 3: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

What is Struts?

Framework of reusable components and taglibraries for building and managing webapplicationsModel-View-Controller architecture

Struts acts as the ControllerAction controlPage building

Page 4: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Models 1 and 2 Architecture

Model 1 Architecture(Traditional)

UI controls all applicationlogic.No separation betweenapplication componentsand how they interactJava code is embedded inHTML code and JSP pageDifficult to develop,debug and maintain

Model 2 ArchitectureSeparates logic from UIdevelopment.Display code is separatefrom page flow controlcode.Servlets control page flow

Page 5: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Struts Architecture

Provides a structured approach to applicationdevelopmentUses a state transition engine (STE) metaphor forpage control.Uses JSP or HTML pages

Page 6: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Struts Elements (1)Action Tag

Used to change control in an applicationMay have other tags nested inside itMay have many Forward tags defined within itMay point to a Java file (action class) for complexcontrol

Forward TagChanges control based on parameter passed from theapplication

name – expected value of passed parameter (e.g. "success" )path – indicates where control will be passed

Page 7: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Struts Elements (2)

Action ClassCustom Java class extending Struts classorg.apache.struts.ActionSupports complex flow logicIncludes "execute" method

ActionForm Class (FormBean)Java classCaches data from page to page movementHandles persistence requirementsNot often used in JDeveloper 10g

Page 8: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Struts Elements

Action (/browseDept.do)Tag used to change control in the application<forward name=“success” path=“/xxy.do”><forward name=“fail” path=“/error.jsp”>

Action Class (actionlogicDept.java)Java class for an action (add complex logic)

Minor ValidationPage Navigation

Logic to select forward: “success” or “fail”

Page 9: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Struts Element Interaction

JSP Page Data Form

Another Page

Database

1. Requestdata

2. Returndata

3. Codedata

4. Pass fordisplay/edit

5. Returnedited data

6. Returndata

7. Pass controlor Action

Another Action 8.Return

updateddata

Page 10: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

ApplicationResources.propertiesfiles

Element/Value pairs (multi-lingual support)Files store string values and global variablesand/or initialization parametersEasy to change properties referenced in manyplaces in the pageCan have multiple files for different languages

Page 11: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Sample .properties files

Page 12: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Simple Struts Application???

Page 13: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

struts-config.xml File

struts-config.xmlCore of Struts !!!XML fileTies all the components of your struts applicationtogether

Page 14: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Sample JDeveloper10gStruts Flow

Page 15: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Sample JDeveloper10gStruts Application

Page 16: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Sample JDeveloper 10gEdit Page

Page 17: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

struts-config.xml

XMLfile – <tags> for all components in theapplication and how they interactTwo main parts:

Form bean areaActionForm/DynaActionForm classes

Action mappings areaActions and re-directions

Page 18: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Inside Struts-config.xml

Form beanJust one reference in Jdev10g!

Complete connection to all ADF BC’s

<struts-config> <form-beans> <form-bean name="DataForm“

type="oracle.adf.controller.struts.forms.BindingContainerActionForm"/>

</form-beans>……</struts-config>

Page 19: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Inside Struts-config.xml

Action mappings

<action path="/browseDeptDAclassName="oracle.adf.controller.struts.actions.DataActionMapping"type="view.BrowseDeptAction" name="DataForm"> <set-property property="modelReference" value="browseDeptPGUIModel"/>

<forward name="success“ path="/browseDeptPG.do"/></action><action path="/browseDeptPG"

className="oracle.adf.controller.struts.actions.DataActionMapping"type="oracle.adf.controller.struts.actions.DataForwardAction"name="DataForm" parameter="/browseDeptPG.jsp"> <set-property property="modelReference"value="browseDeptPGUIModel"/>

</action>

Page 20: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

View-level Struts (tag libs)

HtmlThis library is used to generate standard HTML elements.

Bean Beans are used to provide a number of utility-like operations suchas access data in a cookie.

Logic These libraries provide conditional logic support.

Nested These libraries are used to support nested elements such as anaddress embedded in an Edit Person page.

Template These libraries help create pages based on a template.

Tiles Tiles partition your pages into areas that are static and dynamic toimprove update performance and ease development.

Page 21: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Struts Development

Traditional StrutsCode:

PagesActionsActionClasses

Navigation

ActionFormsValidationData Storage

Struts-config.xml

JDeveloper StrutsDraw:

Page flow

Drag & DropADF data objects

Page 22: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Sample JDeveloper10gStruts Flow

Page 23: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Page Flow Diagram

Main JDev10g interface for Struts

Drag-and-drop functionality makesdevelopment easy!.

Elements added from theComponent Palette or Data Control Paletteare automatically added to the code and viceversa.

Page 24: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Sample JDeveloper PageFlow Diagrams

Simplified flow takingadvantage of ADF Extra data actions to

support complex logic

Page 25: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

JDeveloper Data Controls

Easy drag-and-drop functionality from theData Control PaletteSelect the type of component (JSP, HTML,etc.)

Filtered lists of components appropriate for filetype

“Operations” can be dropped onto elementsin the Page Flow Diagram.

Create, Find, Execute, First, Previous, PreviousSet, Next Set, Last, Delete

Page 26: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

View-Level Struts

Custom Oracle Struts tagsUsed in the view layerSimplify page constructionTie view elements to frameworkDrag & Drop to add:

TablesFormsButtonsEtc.

Page 27: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Components

PageData PageActionData ActionForwardPage LinkPage ForwardNotes & Attachments can be added to anyPage Flow Diagram

Page 28: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Page (basic – but not useful)

Allows you to create a JavaServer PageNo effect on the struts-config.xml fileNot needed - if developing ADFapplications in JDev10g

Page 29: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Data Page (basic ADF element)

Extension of the Struts idea of a pageThe framework will take care of bindingthem to the ADF BC view components.<action path="/dataPage1"className="oracle.adf.controller.struts.actions.DataActionMapping"type="oracle.adf.controller.struts.actions.DataForwardAction" name="DataForm"parameter="unknown"/>

Page 30: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Action (basic – not used in ADF)

Adapts incoming HTTP request to businesslogic to be executed

Model interactionPage navigation

Represents the org.apache.struts.action.Actionelement in the struts-config.xml file.

Page 31: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Data Action(basic ADF element)

Frequently used to simply query data andpass it on to the next element.It can also do non-trivial things such asnavigation to one element or another basedupon some condition.<action path="/dataAction1"className="oracle.adf.controller.struts.actions.DataActionMapping"type="oracle.adf.controller.struts.actions.DataAction"name="DataForm"/>

Page 32: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Forward

Standard Struts elementLinks any two data actions, data pages,forwards, etc…Name/destination pairIt is the Struts equivalent of a “GoTo”.If you create a forward (“success”) from acomponent to one called “B”, it adds the code<forward name="success“ path="/B.do"/>

Page 33: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Page LinkCorresponds to the standard HTML anchor tag

Page tag: Sends you to another page or action.

If you create link in a JSP to take you to page “B”:, it will add thefollowing code<html:link page="/B.do">

<bean:message key="link.B"/> </html:link>

The link page tag tells the page where to go and the message keytag indicates the location of the label text for the link in the.properties file.

link.B=Please take me to page “B”

Page 34: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Page Forward

Simple link to a pageWhen you drag in a page forward it makes thefollowing code:

<action path="/page1" forward="unknown"/>

When you double click on the component and createa UI file (e.g. .jsp file) it will use the name of thefile as the forward destination.Can be used for "child" data pages such as new or editrecord pages.

Page 35: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Using the Struts Elements

Many ways of building an applicationDifferent combinations may be usedMost use data actions and data pagesStandard pages can be used when there is nodata interaction.

Page 36: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

JDeveloper 10gStruts Development

Extended and simplifiedVisual – page flow diagramming toolDrag & Drop integration with ADF ServicesStruts-Tags custom tag libraries

JDev10g provides easiest way to use StrutsMUCH better than 9iMUCH better than anything elseStill not trivial

Page 37: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Tips

Cut and paste code with cautionUse wizardsMost data operations are in two places

XML, Code (Java, HTML)

Don’t renameEven remove is not safe if you have used itDrag and drop adds, it never leaves

In JSP delete from screen AND Structure pane

Bindings area does not clean up.

Save often (certainly prior to each running)Make backups of whole directory

Page 38: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

More Tips

event_...In forward tag in struts_config.xmlevent_Submit defaultevent_ErrorHandler customSaves coding, ADF auto looks for eventsnamed this way (uses “line” name)

&nbsp; - one blank space in HTMLDon’t use “HTML” components whendoing struts – won’t bind

Component Pallette “Struts HTML”

Page 39: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Development Method Tips

1. Ultra-thin client2. Put everything possible into the database.3. Make a view for each screen display andeach screen update4. Applications should never access anythingother than views.

Views wrap functions and procedures.

Page 40: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Required Hardware

Dual 20 inch monitors>=1 GB memory (even if you are not running theDB) 2 GB nice, 4 GB cool> 2 GHz processor

Page 41: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Resources

Oracle JDeveloper 10g Handbook, (Faderman,Koletzke & Dorsey, Oracle Press, 2004)OTN white papersGoogle for help (it will even find the OTNpapers)Post questions on ODTUG, OTN.Get a mentor .

Without one, you will fail one or more projectsBasic Struts book may not help much.

Page 42: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

References

Oracle 10G JDeveloper Handbook,Faderman, Koletzke & Dorsey(Oracle Press, 2004)ISBN: 0072255838Oracle 9iAS: Building J2EEApplications, Morrisseau-Leroy(Oracle Press, 2002)ISBN:0072226145Oracle 9i Application Server PortalHandbook, Vandivier & Cox (OraclePress, 2001) ISBN: 0072222492Oracle 9i JDBC Programming,Jason Price, (Oracle Press, 2002)ISBN: 0072222549 (not needed ifyou use BC4J)Java2: The Complete Reference (5thEdition), Herbert Schildt, (McGraw-Hill, 2002) ISBN: 0072224207

Struts Kick Start, Turner & Bedell,(SAMS, 2002) ISBN: 0672324725Oracle9i XML Handbook, Chang,Scardina & Kiritzov, (Oracle Press,2001) ISBN: 007213495XRefactoring: Improving the Designof Existing Code, Martin Fowler(Addison-Wesley, 1999) ISBN:0201485672Oracle 9i Web Development,Bradley D. Brown (Oracle Press,2001) ISBN: 0072193883The Java Class Libraries – Volumes1, 2, 3, Chan & Lee, (Addison-Wesley)The Java Tutorial (series),Campione, et. al (Addison-Wesley)

Page 43: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Share your Knowledge:Call for Articles

Help contribute your knowledge to the larger Oraclecommunity:

Articles wanted on topics of interest to the Oraclecommunity.

Submit articles, questions, … toIOUG – The SELECT Journal ODTUG – Technical Journal [email protected] [email protected]

Page 44: Dr. Paul Dorsey Dulcian, Inc. - New York Oracle User Group · (basic ADF element) Frequently used to simply query data and pass it on to the next element. It can also do non-trivial

Contact InformationDr. Paul Dorsey – [email protected] website - www.dulcian.com

Developer AdvancedForms & Reports Designer

Handbook

Now available:Oracle 10g JDeveloper Handbook

Design Using UMLObject Modeling