ADF Common Mistakes
ADF Common Mistakes
2
<Insert Picture Here>
4
To err is human and every developer has the
right to make mistakes.
Don't abuse this privilege !
5
ADF Framework
Mistakes
6
Using Internal Packages
7
Binding Classes – The Java in ADF
FacesCtrl* Bindings
8
FacesCtrlHierBinding
Example(s)
<af:table value="#{bindings.allLocations.collectionModel}"
selectionListener="#{myBean.onTableSelect}"/>
9
FacesCtrlHierBinding
10
Replacing FacesCtrlHierBinding
Example(s)
11
Other Mistakes
12
ADF Bindings Mistakes
13
#{data.} Expression Root
Example(s)
<af:outputText value="#{data.demo_v1PageDef.LastName}"/>
return(ApplicationModule)JSFUtils.resolveExpression(
"#{data." + name + ".dataProvider}");
}
14
#{data.} Expression Root
15
Accessing the "bindings" object using EL
Example(s)
16
Accessing the "bindings" object using EL
17
Using page fragments
Example(s)
<af:document id="d1">
...
<f:subview id="sv1">
<jsp:include page="/allDepartments.jsff"/>
</f:subview>
...
</af:document>
18
Using page fragments
19
Adding new Rows
Example(s)
20
Don't fight the framework !
21
Adding new Rows
22
Adding new Rows
• Better
– if you have access to a table, tree or treeTable component
– Does not require knowledge about the binding layer, thus generic
private void createRowInTable(RichTable table){
CollectionModel model = (CollectionModel ) table.getValue();
JUCtrlHierBinding _binding = (JUCtrlHierBinding) model.getWrappedData();
DCIteratorBinding dcIteratorBinding= _binding.getDCIteratorBinding();
Row rw = dcIteratorBinding.getRowSetIterator().createRow();
rw.setNewRowState(Row.STATUS_INITIALIZED);
//insert row to iterator
dcIteratorBinding.getRowSetIterator().insertRow(rw);
//make new row the current
Key k = rw.getKey();
dcIteratorBinding.setCurrentRowWithKey(k.toStringFormat(true));
}
23
ADF Controller Mistakes
24
Task Flow Parameters
Example
<input-parameter-definition>
<name>arg</name>
<value>
#{pageFlowScope.myArg}
</value>
<class>
java.lang.String
</class>
<required/>
</input-parameter-definition>
25
Task Flow Parameters
26
PageFlow scope has Stale Data
Example
27
PageFlow scope has Stale Data
... }
28
PageFlow scope has Stale Data
ADFContext.getCurrent().getApplicationScope();
ADFContext.getCurrent().getSessionScope();
AdfFacesContext.getCurrentInstance().getPageFlowScope();
ADFContext.getCurrent().getRequestScope();
ADFContext.getCurrent().getViewScope();
29
"We should forget about small efficiencies, say about
97% of the time: premature optimization is the root of
all evil"
- Donald Knuth
30
Extending AdfcExceptionHandler
Example(s)
public class MyExceptionHandler extends AdfcExceptionHandler{
public void handleException(FacesContext facesContext,
Throwable throwable,
PhaseId pahseId){
String error = throwable.getMessage();
...
super.handleException(...);
}
}
31
Extending AdfcExceptionHandler
32
Extending AdfcExceptionHandler
…
import oracle.adf.view.rich.context.ExceptionHandler;
public class CustomExceptionHandler extends ExceptionHandler {
public CustomExceptionHandler() {
super();
}
public void handleException(FacesContext facesContext,
Throwable throwable, PhaseId phaseId)
throws Throwable
{
String error_message;
error_message = throwable.getMessage();
if (error_message != null &&
error_message.indexOf("ADF_FACES-30108") > -1)
{
ExternalContext ectx = facesContext.getExternalContext();
ectx.redirect("faces/SessionExpired.jspx");
}
else
{
throw throwable;
}
}
}
33
Extending AdfcExceptionHandler
• Configuration
– Create oracle.adf.view.rich.context.Exceptionhandler
text file and store it in .adf\META-INF\services
– you need to create the “services” folder
– Add the absolute name of your custom exception handler
• Java class that extends ExceptionHandler
• Configuration is framework wide
– Not to be deployed with ADF Library
34
queueActionEventInRegion
Example(s)
richRegion.queueActionEventInRegion(
"#{bindings.Delete.execute}",
null,
null,
false,
0,
0,
PhaseId.INVOKE_APPLICATION);
}
35
queueActionEventInRegion
36
“I don't care about what anything was
DESIGNED to do, I care about what it CAN do.”
Gene Kranz, Apollo 13 (Movie, 1995)
37
queueAction
38
Product Demonstration
queueActionEventInRegion
39
Redirect to Current Page
Example
40
Redirect to Current Page
• JSF doesn't know about ADF Controller and ADF Region states
• Use ControllerContext to create redirect URL
private void redirectToSelf(){
FacesContext fctx = FacesContext.getCurrentInstance();
ExternalContext ectx = fctx.getExternalContext();
String viewId = fctx.getViewRoot().getViewId();
ControllerContext controllerCtx = null;
controllerCtx = ControllerContext.getInstance();
String activityURL = controllerCtx.getGlobalViewActivityURL(viewId);
try{
ectx.redirect(activityURL);
} catch (IOException e) {
//Can't redirect
e.printStackTrace();
}
}
41
Navigation in Bounded Task Flow
Example
Navigation case
42
Navigation in Bounded Task Flow
43
Navigation in Bounded Task Flow
Example
ControllerContext ccontext = ControllerContext.getInstance();
//set the viewId to display
String viewId = "EmployeesView";
ccontext.getCurrentViewPort().setViewId(viewId);
44
Navigation in Bounded Task Flow
45
Navigation in Bounded Task Flow
46
Navigation in Bounded Task Flow
• Helper Method
private MethodExpression createMethodExpressionFromString(String s){
FacesContext fctx = FacesContext.getCurrentInstance();
ELContext elctx = fctx.getELContext();
ExpressionFactory exprFactory =
fctx.getApplication().getExpressionFactory();
MethodExpression methodExpr = exprFactory.createMethodExpression(
elctx,
s,
null,
new Class[]{});
return methodExpr;
}
47
Product Demonstration
Navigation in bounded Task Flow
48
Expression Language
Mistakes
49
Accessing Managed Beans #{requestScope.<…>}
Example(s)
<af:outputText value="#{requestScope.BeanName.LastName}"/>
50
Accessing Managed Beans #{requestScope.<…>}
51
JavaServer Faces
Mistakes
52
JSF Lifecycle - immediate="true"
Example(s)
<af:inputtext value="#{mybacking.firstName}" .../>
<af:commandButton
action="#{mybacking.updateFirstNameVal}" immediate="true"
.../>
53
JSF Lifecycle - immediate="true"
Process Validation
Invoke Application
Render Response
54
ADF Lifecycle "extends" JSF Lifecycle
JSF Lifecycle Phases ADF Lifecycle Phases
Changed yes
View?
no
Render Response
55
Product Demonstration
Immediate = true
56
One to Print on a T-Shirt
57
ADF Faces Component
Mistakes
58
Mixing JSF and HTML
Example(s)
<af:form>
<table>
<tr valign="top">
<td><af:inputText ... label="search" /></td>
<td><af:commandButton ... text="go" /></td>
</tr>
</table>
...
</af:form>
59
Mixing JSF and HTML
60
Examples
61
Inline Style CSS
Example(s)
????
62
Inline Style CSS
• ADF Faces Components are far more complex than simple HTML
elements
• Styles are applied to the root DOM element, not the component itself
• ContentStyle styles the inner area of a component
• Solution: Skinning
<tbody>
<tr id="j_id_id16"
<td>
<label for="j_id_id16::content">
PhoneNumber
</label> =
</td>
<td>
<input id="j_id_id16::content"
type="text" value="650.507.9833"/>
</td></tr>
</tbody>
63
Nesting Tables – Failed Use Case I
Example(s)
64
Nesting Tables – Failed Use Case I
No layout boundaries
65
Not everything that compiles can be shipped!
66
af:forEach, af:iterator
67
af:forEach, af:iterator
• af:forEach
– Replaces JSTL c:forEach, which does not support varStatus
– Only iterates java.util.Lists
• Does not support java.util.Collection
– Use to generate components
• For example: <f:selectItem …>
• Components are remembered by their index
– items created by <af:forEach> should not be added, removed or re-
ordered once the component tree has been created
– Use cases
• Components should be created conditionally based item in the loop.
• Different JSP includes, page templates, and dynamic declarative
components should be included per loop iteration
68
Nesting Tables – Failed Use Case II
Example(s)
<af:table …
value="#{bindings.allDepartments.collectionModel}">
...
<af:column>
<af:table ...
Value="#{bindings.dependentEmployees.collectionModel">
...
</af:table>
</af:column>
</af:table>
69
Nesting Tables
70
af:iterator in table columns
71
af:iterator in table columns
Var="row"
72
Opening popup dialogs
Example(s)
<af:commandButton text="commandButton 1" id="cb1">
<af:showPopupBehavior popupId="popup1"
triggerType="action"
align="afterEnd"
alignId="it1"/>
</af:commandButton>
<af:popup id="popup1" ...>
...
</af:popup>
73
Opening popup dialogs
74
File Upload in ADF Region
75
File Upload in ADF Region
76
JavaScript Mistakes
77
Using the Browser DOM
Example(s)
function cancelEventAndUpdateWithDom(evt){
evt.cancel();
var txtfield1 = document.getElementById("it1::content");
txtfield1.value = "Hello OOW 2010"
}
78
Using the Browser DOM
79
Using the Browser DOM
Example(s)
80
Using the Browser DOM
81
82
Related Oracle Press Books
83