Adf Model Layer

  • October 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Adf Model Layer as PDF for free.

More details

  • Words: 1,679
  • Pages: 28
1/19/2008

ADF Model Layer Dr. Ahmad Taufik Jamil B.Sc.Med(UKM), MD(UKM), M.Comm.Health(Health Management)(UKM), M.Sc(IT)(UPM)

Head IT Department, National University Malaysia

ADF Model Layer • ADF Data Controls – Defining the data controls

• ADF Bindings – Using the data controls

1

1/19/2008

ADF Data Controls; Defining the Data Control

Setup Workspace & Java Class • Create new workspace: “DataControlTest” • Use “Web Application [JSF, EJB]” template. • In “Model” project, create a Java class, called “User”. • Accept all defaults except the name, and using “book.model” as the package name.

2

1/19/2008

Add the followings to the Java class, User.java: package book.model; import java.util.Date; public class User { public User() { } private String name; private Date birthday; public long userAge(int fudgeFactor){ return (long) (21 + fudgeFactor); } public void setName(String name){ this.name=name; } public String getName(){ return name; } public void setBirthday(Date birthday){ this.birthday = birthday; } public Date getBirthday(){ return birthday; }

}

3

1/19/2008

User.java • This java class conforms to the JavaBean standard; – Member variables (attributes) are private – Accessors method

• Compile the file and fix any error

4

1/19/2008

Create the Data Control • 2 ways: – Drag & drop: From the application navigator, drag the java class (User.java) and drop it into the open Data Control Palette – Right-Click Menu: On the User.java file, in the navigator, select Create Data Control from the right-click menu.

• Display and expand the nodes of the Data Control Palette.

5

1/19/2008

The data control definition • Notice that two files have appeared: – User.xml – DataControls.dcx

6

1/19/2008

User.xml <JavaBean xmlns="http://xmlns.oracle.com/adfm/beanmodel" version="10.1.3.36.73" id="User" BeanClass="book.model.User" Package="book.model" isJavaBased="true"> <MethodAccessor IsCollection="false" Type="long" id="userAge" ReturnNodeName="Return"> <ParameterInfo id="fudgeFactor" Type="int" isStructured="false"/>

User.xml • All information to describe User.java • Define al elements in User.java; – each attributes, – getter & setter and – Methods; userAge() method with its output & input

• Never need to edit this file, if you make changes in the User class, just regenerate the data control definition again. • Each java class will have it’s own XML description file

7

1/19/2008

DataControl.dcx <JavaBeanDataControl SupportsTransactions="false" SupportsFindMode="false" SupportsResetState="false" SupportsRangesize="true" SupportsSortCollection="true" SupportsUpdates="false" id="UserDataControl" xmlns="http://xmlns.oracle.com/adfm/datacontrol" FactoryClass="oracle.adf.model.generic.DataControlFactoryImpl" Definition="book.model.User" BeanClass="book.model.User"/>

DataControl.dcx • Index file for all data control within a project. • There will only be one DataControl.dcx to summarize all java class, within the same project folder.

8

1/19/2008

DataControl.dcx • SupportsTransactions is set to "false“. • Try set it to “true” and save. • Refresh Data Control palette, and see what will happen. • Return back it to “false” and save.

Enhance the data control • Serving as an abstract description of a service. • Also allows you to: – Add default values – Control hint (field label & tooltips) – Simple declarative validation

9

1/19/2008

Enhance the data control • Select User.xml file in the navigator and look at the Structure windows. • Double click one of the available attributes; birthday, the attribute editor dialog will display.

10

1/19/2008

Enhance the data control • Select Validation and click New to get started. • Edit the properties of the birthday attribute to add a validation for birthday greater than or equal to “1900-01-01” with an error message. • Click OK

11

1/19/2008

Enhance the data control • Add control hints for Label Text (“Birthday”) • For Format Type (“Simple Date”) • Click “Apply” then “OK”.

12

1/19/2008

Enhance the data control • You will see changes at User.xml file • A java resources bundle file, UserMsgBundle.java is created

13

1/19/2008

New User.xml <JavaBean xmlns="http://xmlns.oracle.com/adfm/beanmodel" version="10.1.3.36.73" id="User" BeanClass="book.model.User" Package="book.model" isJavaBased="true" MsgBundleClass="book.model.UserMsgBundle"> <MethodAccessor IsCollection="false" Type="long" id="userAge" ReturnNodeName="Return"> <ParameterInfo id="fudgeFactor" Type="int" isStructured="false"/>

14

1/19/2008

The New User.xml • Declarative validation rule has been added. • Validation error message and any definition for control hints is not in this file • The string used for the control hints and declarative validation rules are all contained within an array of name value pair, sMessageStrings, within UserMsgBundle.java

UserMsgBundle.java package book.model; import oracle.jbo.common.JboResourceBundle; // --------------------------------------------------------------------// --- File generated by Oracle ADF Business Components Design Time. // --- Custom code may be added to this class. // --- Warning: Do not modify method signatures of generated methods. // --------------------------------------------------------------------public class UserMsgBundle extends JboResourceBundle { static final Object[][] sMessageStrings = { { "birthday_FMT_FORMAT", "yyyy-MM-dd" }, { "birthday_Rule_0", "Errorlah" }, { "birthday_FMT_FORMATTER", "oracle.jbo.format.DefaultDateFormatter" }, { "birthday_LABEL", "Birthday" }}; /**This is the default constructor (do not remove) */ public UserMsgBundle() { } /**@return an array of key-value pairs. */ public Object[][] getContents() { return super.getMergedArray(sMessageStrings, super.getContents()); } }

15

1/19/2008

Summary • Creating Java class – User.java

• Define the data controls – The Data Control definition files: • DataControls.dcx • User.xml

– Data Controls Palette

• Enhance the data controls – Add default values – Control hint (field label & tooltips) – Simple declarative validation

ADF Bindings; Using the Data Control

16

1/19/2008

Create an empty page • On the ViewController project, create a JSF page called “firstPage.jsp” • (by selecting JSF JSP from the web tier/JSF category in the New Gallery. Make sure you select all ADF Faces librarie in step 3 of the wizard and accept the default selection for everything else)

Bind the Attributes • Drag a PanelForm from the ADF Faces Core Component Palette page onto firstPage.jsp • From the Data Control Palette, drag the name attribute and drop it as “ADF Input Text w/Label” inside of the af:panelForm • Repeat this operation for the birthday attribute. This time select Dates>ADF Input Date w/Label

17

1/19/2008

firstPage.jsp

18

1/19/2008

firstPage.jsp • You will notice expression beginning with “#{bindings.” • You will also see references to validator and a converter (f:convertDateTime) which refer to these expression using ‘binding’ object

Examine the ‘Bindings’ • Binding is a reference to data that is being managed by the ADF Model. • When the page is displayed, any attributes required on that page are exposed in a specific object called binding. • Binding object is like a bucket containing all the data that this particular page needs. – Bucket is emptied and refilled with a new set of data as the user navigates between pages.

19

1/19/2008

Attribute Binding Editor • In the JSF visual editor (design tab), right click on the name field, select Edit Binding. • This will display Attribute Binding Editor for the field (name). • Showing that is indeed linked with the UserDataControl (Data control)- refer to DataControl.dcx. • The information exist is in Page Definition File (Another XML metadata)



The information shown in this dialog is defined in Page Definition file; firstPagePageDef.xml

20

1/19/2008

• In the visual editor, select Go To Page Definition from right-click menu • See ‘firstPagePageDef.xml’ <pageName>PageDef.xml

<pageDefinition xmlns="http://xmlns.oracle.com/adfm/uimodel" version="10.1.3.41.57" id="bindingPageDef“ Package="view.pageDefs"> <parameters/> <executables>

21

1/19/2008

firstPage.jsp

<pageDefinition xmlns="http://xmlns.oracle.com/adfm/uimodel" version="10.1.3.41.57" id="bindingPageDef“ Package="view.pageDefs"> Refer to <parameters/>

DataControl.dcx <executables> Refer to section <executables> in the same file

22

1/19/2008

Linkage from page.. • Binding expression (#{bindings.birthday.inputValue} in JSF) to • AttributeValues (Page Definition File) to • Iterator (Page Definition File) to • Data Control.

#{bindings.birthday.inputValue} • bindings : data managed by ADFm • birthday : attribute mapped in Page Definition file • inputValue : actual data of the attribute in runtime. • Format: #{bindings.MyBindingObject.propertyName.attributeName}

23

1/19/2008

“Bind to Data” dialog

“Bind to Data” dialog

24

1/19/2008

Contents • ADF Bindings – Bindings (Most cases we are interested in data listed under this node, it contain the available data in the context of the current page) – Data (use to access the bound data element of any page within application)

• JSF Managed Beans – Contain managed bean

• JSP Objects – General expression scope available in JSPs, such as sessionScope, coookies etc.

Binding Master File • DataBindings.cpx • Master mapping file that the framework uses to associate a page (JSF), with Page Definition file

25

1/19/2008

01: 02: <Application xmlns=http://xmlns.oracle.com/adfm/application version="10.1.3.41.57" URL path of the id="DataBindings" SeparateXMLFiles="false“ Package="viewcontroller" ClientType="Generic">

page 03: 04: 05:

<pageMap> <page path="/firstPage.jsp" usageId="firstPagePageDef"/>

06: 07: 08:

<pageDefinitionUsages> <page id="firstPagePageDef“ path="viewcontroller.pageDefs.firstPagePageDef"/>

List references to page definition

09: 10: 11: 12:

Web.xml <param-name>CpxFileName <param-value>viewcontroller.DataBindings

26

1/19/2008

Summary • Creating JSF page – firstPage.jsp

• Binding File – DataControl.dcx : define data controls – firstPagePageDef.xml : define binding used on a particular page – DataBinding.cpx : define the relationship between PageDef files and page file (jsf). It also define the data controls used within the project.

• Reference to DataBinding.cpx – Web.xml

Review of files Description

Files

Java class/EJB

User.java

Data Control Definition User.xml

DataControls.dcx

Notes Describe User.java. Each java class will have it’s own .xml Index file for all data control. Only one dcx file for each project folder.

JSP/JSF

firstPage.jsp

Page Definition

firstPagePageDef.xml Contain data required for the jsp file

Binding master file

DataBindings.cpx

Master mapping to associate jsp file with page definition file

Others

web.xml

Defining the name & location of the DatBinding.cpx

27

1/19/2008

Dialog box Dialog box

Notes

Attribute editor

For user.xml

Attribute binding editor For field, to show mapping in page definition for field in jsp Bind to data dialog

To browse available object that can be bound to an attribute Create expression for jsp file

28

Related Documents

Adf Model Layer
October 2019 15
Adf
July 2020 5
Esquema Adf
May 2020 2
Adf Tutorial
May 2020 5
Adf Soru Bankasi
May 2020 5