Upload
duongkhanh
View
232
Download
0
Embed Size (px)
Citation preview
1/19/2008
1
ADF Model Layer
Dr. Ahmad Taufik JamilB.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/19/2008
2
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.
1/19/2008
3
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;
}
}
1/19/2008
4
User.java
• This java class conforms to the JavaBean
standard;
– Member variables (attributes) are private
– Accessors method
• Compile the file and fix any error
1/19/2008
5
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.
1/19/2008
6
The data control definition
• Notice that two files have appeared:
– User.xml
– DataControls.dcx
1/19/2008
7
User.xml
<?xml version="1.0" encoding="UTF-8" ?>
<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">
<Attribute Name="birthday" Type="java.util.Date"/>
<Attribute Name="name" Type="java.lang.String"/>
<MethodAccessor IsCollection="false" Type="long" id="userAge"
ReturnNodeName="Return">
<ParameterInfo id="fudgeFactor" Type="int" isStructured="false"/>
</MethodAccessor>
<ConstructorMethod IsCollection="false" Type="void" id="User"/>
</JavaBean>
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
1/19/2008
8
DataControl.dcx
<?xml version="1.0" encoding="UTF-8" ?>
<DataControlConfigs xmlns="http://xmlns.oracle.com/adfm/configuration"
version="10.1.3.36.73" Package="model" id="DataControls">
<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"/>
</DataControlConfigs>
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.
1/19/2008
9
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
1/19/2008
10
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.
1/19/2008
11
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
1/19/2008
12
Enhance the data control
• Add control hints for Label Text
(“Birthday”)
• For Format Type (“Simple Date”)
• Click “Apply” then “OK”.
1/19/2008
13
Enhance the data control
• You will see changes at User.xml file
• A java resources bundle file,
UserMsgBundle.java is created
1/19/2008
14
New User.xml
<?xml version="1.0" encoding="UTF-8" ?>
<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">
<Attribute Name="birthday" Type="java.util.Date" DefaultValue=""
PrecisionRule="false" Precision="0" Scale="0">
<CompareValidationBean xmlns="http://xmlns.oracle.com/adfm/validation"
OnAttribute="birthday" ResId="birthday_Rule_0"
OperandType="LITERAL" Inverse="false"
CompareValue="1900-01-01"
CompareType="GREATERTHANEQUALTO"/>
</Attribute>
<Attribute Name="name" Type="java.lang.String"/>
<MethodAccessor IsCollection="false" Type="long" id="userAge"
ReturnNodeName="Return">
<ParameterInfo id="fudgeFactor" Type="int" isStructured="false"/>
</MethodAccessor>
<ConstructorMethod IsCollection="false" Type="void" id="User"/>
</JavaBean>
1/19/2008
15
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.javapackage 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());
}
}
1/19/2008
16
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
1/19/2008
17
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 birthdayattribute. This time select Dates>ADF Input Date w/Label
1/19/2008
18
firstPage.jsp
<af:panelForm>
<f:facet name="footer"/>
<af:inputText value="#{bindings.name.inputValue}"
label="#{bindings.name.label}"
required="#{bindings.name.mandatory}"
columns="#{bindings.name.displayWidth}">
<af:validator binding="#{bindings.name.validator}"/>
</af:inputText>
<af:selectInputDate value="#{bindings.birthday.inputValue}"
label="#{bindings.birthday.label}"
required="#{bindings.birthday.mandatory}">
<af:validator binding="#{bindings.birthday.validator}"/>
<f:convertDateTime pattern="#{bindings.birthday.format}"/>
</af:selectInputDate>
</af:panelForm>
1/19/2008
19
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.
1/19/2008
20
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
1/19/2008
21
• In the visual editor, select Go To Page
Definition from right-click menu
• See ‘firstPagePageDef.xml’
<pageName>PageDef.xml
<?xml version="1.0" encoding="UTF-8" ?>
<pageDefinition xmlns="http://xmlns.oracle.com/adfm/uimodel"
version="10.1.3.41.57" id="bindingPageDef“ Package="view.pageDefs">
<parameters/>
<executables>
<iterator id="UserDataControl_rootIter" RangeSize="10" Binds="root“ DataControl="UserDataControl"/>
</executables>
<bindings>
<attributeValues id="name" IterBinding="UserDataControl_rootIter">
<AttrNames>
<Item Value="name"/>
</AttrNames>
</attributeValues>
<attributeValues id="birthday“ IterBinding="UserDataControl_rootIter">
<AttrNames>
<Item Value="birthday"/>
</AttrNames>
</attributeValues>
</bindings>
</pageDefinition>
1/19/2008
22
firstPage.jsp
<af:panelForm>
<f:facet name="footer"/>
<af:inputText value="#{bindings.name.inputValue}"
label="#{bindings.name.label}"
required="#{bindings.name.mandatory}"
columns="#{bindings.name.displayWidth}">
<af:validator binding="#{bindings.name.validator}"/>
</af:inputText>
<af:selectInputDate value="#{bindings.birthday.inputValue}"
label="#{bindings.birthday.label}"
required="#{bindings.birthday.mandatory}">
<af:validator binding="#{bindings.birthday.validator}"/>
<f:convertDateTime pattern="#{bindings.birthday.format}"/>
</af:selectInputDate>
</af:panelForm>
<?xml version="1.0" encoding="UTF-8" ?>
<pageDefinition xmlns="http://xmlns.oracle.com/adfm/uimodel"
version="10.1.3.41.57" id="bindingPageDef“ Package="view.pageDefs">
<parameters/>
<executables>
<iterator id="UserDataControl_rootIter" RangeSize="10" Binds="root“ DataControl="UserDataControl"/>
</executables>
<bindings>
<attributeValues id="name" IterBinding="UserDataControl_rootIter">
<AttrNames>
<Item Value="name"/>
</AttrNames>
</attributeValues>
<attributeValues id="birthday“ IterBinding="UserDataControl_rootIter">
<AttrNames>
<Item Value="birthday"/>
</AttrNames>
</attributeValues>
</bindings>
</pageDefinition>
Refer to
DataControl.dcx
Refer to section
<executables> in the
same file
1/19/2008
23
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}
1/19/2008
25
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
1/19/2008
26
01: <?xml version="1.0" encoding="UTF-8" ?>
02: <Application xmlns=http://xmlns.oracle.com/adfm/application version="10.1.3.41.57"
id="DataBindings" SeparateXMLFiles="false“ Package="viewcontroller" ClientType="Generic">
03: <pageMap>
04: <page path="/firstPage.jsp" usageId="firstPagePageDef"/>
05: </pageMap>
06: <pageDefinitionUsages>
07: <page id="firstPagePageDef“ path="viewcontroller.pageDefs.firstPagePageDef"/>
08: </pageDefinitionUsages>
09: <dataControlUsages>
10: <dc id="UserDataControl" path="book.model.UserDataControl"/>
11: </dataControlUsages>
12: </Application>
URL path of the
page
List references to page definition
Web.xml
<context-param>
<param-name>CpxFileName</param-name>
<param-value>viewcontroller.DataBindings</param-value>
</context-param>
1/19/2008
27
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 Notes
Java class/EJB User.java
Data Control Definition User.xml
DataControls.dcx
Describe User.java. Each java class will
have it’s own <filename>.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