ADF Code Corner How to cancel an edit form, undoing changes with ADFm savepoints

Similar documents
ADF Code Corner. 90. Filtering ADF bound lists. Abstract: twitter.com/adfcodecorner

ADF Code Corner How-to declaratively build a master-detail behavior with DVT components. Abstract: twitter.com/adfcodecorner

ADF Code Corner. 64. How-to implement a Select Many Shuttle with pre- selected values. Abstract: twitter.com/adfcodecorner

ADF Code Corner How-to enforce LOV Query Filtering. Abstract: twitter.com/adfcodecorner

ADF Code Corner How-to use the af:autosuggestbehavior component tag with ADF bound data sources. Abstract: twitter.

ADF Code Corner How-to bind custom declarative components to ADF. Abstract: twitter.com/adfcodecorner

ADF Mobile Code Corner

ADF Code Corner How-to further filter detail queries based on a condition in the parent view using ADF BC. Abstract: twitter.

ADF Code Corner. 70. How-to build dependent list boxes with Web Services Business Services. Abstract: twitter.com/adfcodecorner

ADF Code Corner. 048-How-to build XML Menu Model based site menus and how to protect them with ADF Security and JAAS. Abstract:

ADF Code Corner. 97. How-to defer train-stop navigation for custom form validation or other developer interaction. Abstract: twitter.

Mastering Oracle ADF Task Flows. Frank Nimphius Principal Product Manager Oracle JDeveloper / ADF

ADF Mobile Code Corner

ADF Code Corner. 016-How-to customize the ADF Faces Table Filter. Abstract: twitter.com/adfcodecorner

ADF Code Corner Implementing auto suggest functionality in ADF Faces. Abstract:

ADF Code Corner. 65. Active Data Service Sample Twitter Client. Abstract: twitter.com/adfcodecorner

ADF Code Corner How-to launch a popup upon rendering of a page fragment in a region using JSF 2. Abstract: twitter.

ADF Code Corner How-to restrict the list of values retrieved by a model driven LOV. Abstract: twitter.com/adfcodecorner

ADF Mobile Code Corner

ADF Mobile Code Corner

ADF Code Corner. 71. How-to integrate Java Applets with Oracle ADF Faces. Abstract: twitter.com/adfcodecorner

ADF Code Corner How-to build a reusable toolbar with Oracle ADF Declarative Components. Abstract: twitter.com/adfcodecorner

ADF Code Corner How-to show a glasspane and splash screen for long running queries. Abstract: twitter.com/adfcodecorner

1 Copyright 2011, Oracle and/or its affiliates. All rights reserved.

ADF Hands-On. Understanding Task Flow Activities / 2011 ADF Internal Enterprise 2.0 Training. Abstract:

ADF Region Interaction: External Train Navigation

ADF Code Corner How-to use Captcha with ADF Faces and Oracle ADF. Abstract: twitter.com/adfcodecorner

ADF Code Corner. Oracle JDeveloper OTN Harvest 10 / Abstract: twitter.com/adfcodecorner

Oracle Fusion Middleware 11g: Build Applications with ADF I

1 Copyright 2011, Oracle and/or its affiliates. All rights reserved.

ADF Code Corner. Oracle JDeveloper OTN Harvest 01 / Abstract: twitter.com/adfcodecorner

Database Programming with SQL

ADF Code Corner. Oracle JDeveloper OTN Harvest 02 / Abstract: twitter.com/adfcodecorner

Oracle Fusion Middleware 11g: Build Applications with ADF I

ADF Code Corner. Oracle JDeveloper OTN Harvest 09 / Abstract: twitter.com/adfcodecorner

Take Your Oracle Forms on the Road Using ADF Mobile. Mia Urman, OraPlayer & Denis Tyrell, Oracle Corporation

Oracle Fusion Middleware 11g: Build Applications with ADF Accel

Oracle Retail Accelerators for WebLogic Server 11g

Oracle Middleware 12c: Build Rich Client Applications with ADF Ed 1 LVC

Exam Questions 1Z0-419

Oracle ADF 11g: New Declarative Validation, List of Values, and Search Features. Steve Muench Consulting Product Manager Oracle ADF Development Team

User Guide Using AuraPlayer

ADF OAF Who Cares? You Do! Oracle Applications Framework / Application Development Framework - Which way do I go?

Weak Levels of Consistency

Oracle Fusion Developer Guide (ISBN: ) Preview Chapter 1. The Quick Lerner s Guide to Oracle Fusion Web Application Development PREVIEW

Oracle Application Development Framework Overview

AuraPlayer Server Manager User Guide

Oracle 1Z Oracle Application Development Framework 12c Essentials. Download Full Version :

<Insert Picture Here> JDeveloper Treasure Hunt

OES Permission Checks in ADF Task Flows

OIG 11G R2 Field Enablement Training

Oracle ADF Faces Cookbook

Chapter 9: Transactions

Oracle JDeveloper/Oracle ADF 11g Production Project Experience

Oracle Developer Day

Oracle Exam 1z0-419 Oracle Application Development Framework 12c Essentials Version: 7.0 [ Total Questions: 87 ]

ADF Code Corner. Oracle JDeveloper OTN Harvest 12 / 2011 & 01 / Abstract: twitter.com/adfcodecorner

Oracle Developer Day

Achieving the Perfect Layout with ADF Faces RC

Introduction to Computer Science and Business

ADF Code Corner. Oracle JDeveloper OTN Harvest 04 / Abstract: twitter.com/adfcodecorner

Chapter 14: Transactions

Understanding Oracle ADF and its role in the Oracle Fusion Platform

TIA Academy Catalog. TIA Academy Catalog

Copyright 2012, Oracle and/or its affiliates. All rights reserved.

Building Extendable Oracle ADF Applications with Embedded Mule ESB. Miroslav Samoilenko. January 2008

JDeveloper Downloading a Workspace for WebCenter Spaces Development

Chapter 15: Transactions

<Insert Picture Here> Advanced ADF Faces. Frank Nimphius Principal Product Manager

Transaction Concept. Two main issues to deal with:

Oracle Fusion Middleware

Question No: 1 In which file should customization classes be specified in the cust-config section (under mds-config)?

How Oracle Does It. No Read Locks

Transaction Management Chapter 11. Class 9: Transaction Management 1

New Features Guide Sybase ETL 4.9

1Z0-430

WebCenter Portal Task Flow Customization in 12c O R A C L E W H I T E P A P E R J U N E

General Coding Standards

<Insert Picture Here> Accelerated Java EE Development: The Oracle Way

Implementing a Numerical Data Access Service

Moving Forward with Oracle Forms

Building Database-Centric Web Applications Using. Oracle HTML DB

Contents I Introduction 1 Introduction to PL/SQL iii

Overview. Principal Product Manager Oracle JDeveloper & Oracle ADF

Oracle ILM Assistant Installation Guide Version 1.4

Customizing Oracle Identity Governance: Populating Request Attributes

Functional. Pattern Embeding Regions inside PopUp Windows

<Insert Picture Here> How to Debug Oracle ADF Framework Applications

PROCEDURAL DATABASE PROGRAMMING ( PL/SQL AND T-SQL)

<Insert Picture Here> Oracle Application Framework (OAF): Architecture, Personalization, and Extensibility in Oracle E-Business Suite Release 12

Chapter. An Introduction to Oracle JDeveloper and Oracle ADF

MAKING THE BUSINESS CASE MOVING ORACLE FORMS TO THE WEB

Backup types. Excerpted from

Developing Cross Device Mobile Applications

A Closer Look at XPages in IBM Lotus Domino Designer 8.5 Ray Chan Advisory I/T Specialist Lotus, IBM Software Group

Chapter 13. Concurrency Control. In This Chapter. c Concurrency Models c Transactions c Locking c Isolation Levels c Row Versioning

RESEARCH DATABASE. When you come to the Marine Mammal Research Database, you will see a window like the one below.

<Insert Picture Here> The Oracle Fusion Development Platform: Oracle JDeveloper and Oracle ADF Overview

Roadmap of This Lecture

Transaction Concept. Chapter 15: Transactions. Example of Fund Transfer. ACID Properties. Example of Fund Transfer (Cont.)

Transcription:

ADF Code Corner 0007. How to cancel an edit form, undoing changes with ADFm Abstract: This how-to document describes one of the two options available to cancel an edit form in ADF Faces RC without a required field message being raised by the client validator. Canceling an edit form with ADF requires more than just setting the immediate property set to true on the command button. It requires some housekeeping for the changes performed on the ADF binding layer. twitter.com/adfcodecorner Author: Frank Nimphius, Oracle Corporation twitter.com/fnimphiu 08-JAN-2009

Oracle ADF Code Corner is a loose blog-style series of how-to documents that provide solutions to real world coding problems. Disclaimer: All samples are provided as is with no guarantee for future upgrades or error correction. No support can be given through Oracle customer support. Please post questions or report problems related to the samples in this series on the OTN forum for Oracle JDeveloper: http://forums.oracle.com/forums/forum.jspa?forumid=83 Introduction Two strategies exist to implement a cancel button for an ADF Faces / ADF edit form that uses client-side and server side validation: a) restoring state with a save point set in ADFm and b) a client Java method exposed on the ADF Business Component business service. Both strategies are similar in that they use the immediate property on a ADF Faces command button to cancel the edit, but are different in their implementation of the data clean-up. When discussing the problem with Steve Muench, he came up with the the declarative approach that uses a bounded taskflow to clean up the data modification when cancel is pressed. Its a straight forward approach that is easy understand and implement. In a previous article, we introduced a Java based solution that didn't use any save point feature but a pure code centric approach. The Java based approach however falls a bit short when a record was deleted and now needs to be recovered. In this article, the focus is on model save points that can be set programmatically or implicit in bounded taskflows. Problem Description The problem is based on a simple usecase: A user enters a page to either create a new record or update an existing record. After navigating to the edit form, the user starts modifying the form data and then decides to forget about the changes. So he presses the cancel button of the edit form in which case the ADF Faces RC response might be as shown below 2

There are two issues here: i) The user didn't provided all the required field values before pressing "cancel" and ii) a new record has been created in the ADF iterator binding, which awaits clean up. About ADFm Savepoints The ADF model (ADFm) save point is a snapshot of the transaction state. Restoring a model save point rolls back the current transaction up to the point when the save point was created. ADF model save points can be created explicitly by the application developer or implicit by the ADFc controller. ADFc implicitly creates a save point if a bounded taskflow is entered without starting its own transaction. The save-point is used if the user abandons the bounded taskflow, for example using the browser back button, or when a return activity has the restore-save-point element set. Implicit ADFm Savepoints Implicit save points are configured on bounded taskflows. As soon as a navigation enters the bounded taskflow, a snapshot of the current transaction is taken to revert to the state before entering the bounded taskflow if needed. In the example below, the bounded taskflow contains the logic for an edit form for employee data. The router determines whether it is a "new create" or an "edit" request for an existing employee record. In both cases the "Edit" view is displayed to the user to add or modify the data. 3

The edit form in the "Edit" view has a "submit" button and a "cancel" button. It is important to point out that the immediate property on the cancel button must be set to true to avoid field validation errors when canceling the form. The cancel button navigates the request to the "Submit" return activity, whereas the cancel button routes it to the "cancel" return activity. To enable transaction handing in a bounded taskflow, the taskflow itself must be configured. In this example, the bounded taskflow is set to use a shared Data Control Scope (which also is the default setting) and has its Transaction property set to requires-transaction. The Transaction property setting defines that the bounded taskflow either leverages an existing transaction from the calling taskflow or starts a new transaction if none exists. In his upcoming February/March column for Oracle Magazine, Steve Muench explains in detail how the declarative transaction works in bounded taskflows and you find a reference to all his Oracle Magazine articles at the end of this paper. For now, it is enough to understand that the transaction either exists or is created in the bounded taskflow. 4

The return activities differ in their settings for the End Transaction and Restore Save Point properties. For the submit button, there is no need to restore the save point and all you need to do is to set the End Transaction property to commit. Commit? Yes commit! Why? Because I said so! The reason why the End Transaction needs to be set to commit is that the bounded taskflow may need to create a new transaction if no existing one exists. To see the applied changes in the caller taskflow, the changes must be committed. If there exist a transaction - opened by the parent flow (or view port as it is more precise to say) - then the commit is ignored and the return happens without committing the transaction so that no damage is done to uncommitted data states. The settings for the "cancel" return activity are rollback for the End Transaction and Restore Save Point set to true. Similar, if a new transaction was created by the bounded taskflow, the rollback will 5

undo all the changes. If an existing transaction was used, a roll back to the previous stored save point will restore the state that existed before entering the taskflow. Explicit ADFm Savepoints in ADF Task Flow The explicit save point use case is in analogy to the previous article though a bit smarter in the approach. Instead of exposing a method on the Application Module, this approach programmatically sets and restores ADFm save points. The nice thing about this approach is that it not only works for bounded taskflows but unbounded taskflows as well. 6

The flow in the image above is similar to the flow shown with the bounded taskflow. The router activity directs the request to the "Edit" view, either for creating a new employee record or a for editing an existing record. Again it is important to notice that the cancel button on the "Edit" form has its immediate property set to true to avoid filed validation errors. The ADFm save points are created and restored by method call activities that reference a method in a managed bean. Since the managed bean methods doesn't hold any state, it can be configured with a None scope so it doesn't hang around unused in memory. The save point methods are public void restore_action() { String sph = (String) rctx.getpageflowscope().get("adfmsavepoint"); BindingContext bctx = BindingContext.getCurrent(); DCDataControl dcdatacontrol = bctx.getdefaultdatacontrol(); dcdatacontrol.restoresavepoint(sph); } public void createadfmsavepoint(){ BindingContext bctx = BindingContext.getCurrent(); DCDataControl dcdatacontrol = bctx.getdefaultdatacontrol(); String sph = (String) dcdatacontrol.createsavepoint(); rctx.getpageflowscope().put("adfmsavepoint",sph); } 7

The save point created by the createadfmsavepoint method is stored in the taskflow's pageflowscope where it is accessed from the restore_action method. Note that the lifetime of a save point is limited to until the transaction is committed or rolled back. In other words, you cannot commit a form to then use a save point to restore the old state. Something to keep in mind when choosing one or the other approach. The method call activity definitions used in this example are <method-call id="createsavepoint"> <method>#{browsedepartmentbean.createadfmsavepoint}</method> <outcome> <fixed-outcome>goahead</fixed-outcome> </outcome> </method-call> <method-call id="restore"> <method>#{browsedepartmentbean.restore_action}</method> <outcome> <fixed-outcome>return</fixed-outcome> </outcome> </method-call> Download Samples The two sample workspaces are build against the HR demo schema using Oracle JDeveloper 11 production. You can download the sample workspacess from the ADF Code Corner website: http://www.oracle.com/technetwork/developer-tools/adf/learnmore/index-101235.html RELATED DOCOMENTATION Steve Muench s Oracle Magazine columns - http://www.oracle.com/technology/products/jdev/tips/muench/oramag/index.html Adding to a Task Flow - Adding to a Task Flow - http://download.oracle.com/docs/cd/e15523_01/web.1111/b31974/taskflows_complex.htm#c HDBDJBI 8