Posts

Showing posts from 2009

Conditionally displaying search form parameters

ADF helps you to build search forms declaratively using model-driven af:query and af:quickQuery components. To learn more about this topic, please refer Chapter 26 Creating ADF Databound Search Forms in Fusion Dev. Guide. If you use ADF Business Components for building your business services, ViewCriteria defined on your ViewObject act as the model for the af:query component. af:query component (backed up with ViewCriteria) is smart enough to address most of the common use cases declaratively. However there may be some use case scenarios, where developers need to go beyond the declarative development approach and dirty their hands a bit:) One such scenario is displaying search form prameters, conditionally. In other words, parameters in the query panel needs to be displayed based on certain conditions. Let me try explaining a possible solution for this use case. Please remember that each query parameter displayed in af:query is modeled by a ViewCrieteriaItem instance. Apparently,...

Customizing ELResolver to intercept the evaluation of ADF binding values

ELResolver enables customization of variable and property resolution behavior for EL expression evaluation. In case you are not familiar with this topic, please see one of my previous post to get a feel of this concept. Very recently, I noticed an interesting use case scenario related to this topic. Here the requirement is that, whenever business user modifies a date field displayed on the web UI, the same value needs to be converted to a specific time zone by the system based on certain business rules before saving to database. One possible solution is to use custom ELResolver to intercept the setters for the attribute value. Interestingly, a customized ELResolver created by sub classing javax.el.ELResolver work for EL expressions that use managed beans, but fail for ADF binding values - modified values are not getting passed to model . So, what next? Your friend is javax.el.MapELResolver here. Why should I specifically use javax.el.MapELResolver ? Before answering this questi...

VIewObject based on 'pivot query'

Image
I have seen few posts in ADF discussion forums asking for solutions to transpose database table rows in to columns. Apparently, this turns out to be s a query related to the underlying RDBMS. Attaching a simple demo application that transforms Employee Table in columnar from as shown below. [If you use Oracle 11g, pivot operator will help you to achieve the same behavior. The above sample is not using pivot operator] You can download the sample workspace from here . [Runs with Oracle JDeveloper 11g R1 PS1 + HR Schema]

Retrieving deleted Entity Objects

I have seen a couple of use cases where developers need to iterate through the deleted Entity Objects and perform validations based on various conditions. Steve shared some pointers, which helped me to find a solution. The following code snippet may help you to identify the deleted entities. public class EmployeesImpl extends EntityImpl { public ArrayList<EntityImpl> findDeletedEmployees() { ArrayList<EntityImpl> deletedList = new ArrayList<EntityImpl>(); Iterator iterator = this.getEntityDef(). getAllEntityInstancesIterator (this.getDBTransaction()); while (iterator.hasNext()) { EmployeesImpl emp = (EmployeesImpl)iterator.next(); if (emp.getEntityState() == Entity.STATUS_DELETED) { // Keep soft ref. if worried on GC deletedList.add(emp); } } return deletedList; } // Rest ...

Creating a Data Capture Form using EJB + JPA and ADF Binding

Image
Java EE technology stack has been improved tremendously in recent past. However, a closer look at this technology spectrum reveals the visible gap that exists between the UI and Service layers. Core Java EE stack really lacks a smart glue layer that avoids large chunk of boiler plate code used for wiring UI with business data. For a typical Java EE business application, we can say that about 20-25% coding effort is being spent for wiring UI to the data from business services and other common UI manipulations such as synchronizing master-child relations, querying entities and displaying results, navigating between records, invoking actions etc. Binding the UI with EJB Is there any matured binding solution available for Java EE technology stack? Answer is YES, Your friend is ADF binding layer who can really help you to bridge the gap between UI and business service layer. Seeing is Believing So let us try building a data capture form using Java EE technology stack with the help ...

Displaying pre-executed query result in a search form

Image
I recently encountered an interesting use case related to Search Binding. Requirement is to display the result of pre executed query in a search form embedded inside a popup dialog. Developer tried executing the query from popupFetchListener, but no success in displaying the search result back on the form. Always search result component comes empty. What has gone wrong here? Before start seeing the implementation part, let us try to understand the model driven query component's runtime behavior. <af:query> component's binding(search binding) by default, follow 'AutoQuery-or-ClearRowSet' behavior. In simple words, search binding for <af:query> component will try to perform either of the below steps(AutoQuery or ClearRowSet) while rendering the page where the component is embedded. AutoQuery : <af:query> component follows model driven rendering approach. Obviously the ViewCriteria defined in the ViewObject, decides query component's runtime beha...

Accessing web tier variable values from the business components in a groovy way

Image
Groovy is an amazing dynamic language with lots of unnoticed features. One feature that I like most is the dynamism that can be introduced to an enterprise application at runtime. To know more about the groovy support in ADF, please go through this white paper : Introduction to Groovy This 'dynamism' fits pretty well for an ADF based application in many scenarios. However, there are few cases where this feature is being used in a non groovy way :) Accessing web layer data from business components Rule of thumb for designing a system is that client layer can  depend upon your business service layer, not the other way around. This provides more flexibility and extensibility to the system. Your build tool (say for e.g.: maven) may also expect a unidirectional dependency, to resolve dependencies without getting into infinite loops. However, there are some use cases where EntityObjects or ViewObjects needs to be initialized with values from the client side(web tier)....

Entity Object based on a PL/SQL Package API

A simple demo application that uses Entity Object based on the Stored Procedure is attached here . More details can be found in Developer's Guide, section 37.5 Basing an Entity Object on a PL/SQL Package PS: Unzip the attachment and run the script(StoredProcedureExample/script) to set up the required DB objects for running this demo

Reset the content of a web page

Resetting the page contents or undoing the changes made by a user is a very common use case scenario in Rich Internet Applications. The 'reset action' should skip all validations defined on the current page and page contents needs to restored from the underlying data layer. Some of the web frameworks support this feature out of the box. Let me try explaining possible ways to reset a page when developing applications using ADFFaces. 1. <af:resetButton> As the name suggests, af:resetButton resets the contents of a form. Please note that developer doesn't have much control here as he/she might not be able to bind any action method with this built in reset button. <af:resetButton text="ResetButton" id="rb1"/> 2. <af:resetActionListener> This tag is usually bound to an action source like command button to reset all submitted values whenever an action is triggered. Obviously this gives more control to the developer as the action sourc...

Decorate JSF managed bean with custom Annotations

Image
Java Annotatons   has been widely accepted by enterprise application developers. It really free up developers from writing down tons of boilerplate code which is used for business service invocation or basic infrastructural set up like initializing the service context or getting handle to some core runtime services etc. This blog post is mainly intended to take you through the possibilities of using annotation while building enterprise solutions. There are definite advantages if you use this tool judiciously. Few highlights are: Reduces the boilerplate code in your business tier. Adds dynamism to your code. Greater control on the implementation part, as the logic is abstracted  from the developers. High Extensibility etc... JSF managed bean and custom ADF flavored annotations A closer look at the source code of a typical web application may reveal fair amount of boilerplate code that spread across managed beans on the client tier. This repetitive piece of code ma...

Format date for a Locale

A very common use case related to localization is that, formatting the date specific to a user-selected locale. Following code snippet will help you to identify the default pattern corresponding to a locale. String pattern = ((SimpleDateFormat)DateFormat.getDateTimeInstance(SimpleDateFormat.FULL, SimpleDateFormat.LONG, locale)).toPattern(); Your jsf page snippet may look like: <af:inputDate label="Date:" id="id1" value="#{viewScope.TestBean.date}" binding="#{viewScope.TestBean.inputDate}" partialTriggers="soc1"> <af:convertDateTime type="both" timeZone="#{viewScope.TestBean.timeZone}" locale="#{viewScope.TestBean.locale}" pattern="#{viewScope.TestBean.pattern}" /> </af:inputDate> You can downloa...

How to Skip Validation?

Image
ADF has a very robust validation framework. Validations can be added at different layers (view, model and business services) based on your application's requirement. To learn more about the ADF validation framework, please go through the Fusion Developer's Guide for Oracle Application Development Framework . That said, however, in a real business scenario there are cases where the validation needs to be skipped (or by passed) conditionally while submitting the form. This post discusses this topic with some common use cases. Keep immediate=true A very common way to skip validation is by keeping the value for immediate attribute as 'true' for the UIComponents. Immediate attribute allow processing of components to move up to the Apply Request Values phase of the lifecycle. Use case scenario While canceling a specific action, system should not perform the validation. One possible way to achieve this is by keeping immediate=true associated with UI element. To know ...

How to keep track of modified values of controls in a JSF application?

I recently encountered an interesting use case where ADF Faces is used for the view layer and the data(model) is persisted in LDAP Store. Now the requirement is to identify the modified records/attributes and perform the update only on these records. There may be different ways to achieve this, say for example using container like Spring with AOP. But, is there any other smart approach without adding extra layer to my application's technology stack? Answer is 'Yes'. Let us explore one possible approach for this use case scenario. ELResolver The solution is based on customized ELResolver. We know that backing beans are bound to the view(jsf pages) using Expression Language(EL). ELResolver actually resolves thesa 'binding expressions' at runtime. So idea is to intercept in the invocation of setters for the backing beans through a customized ELResolver. And add the logic to track the modified attributes at this point. JSF specification enables to add customized javax.e...

Tips on LOV Runtime

Image
Do you know how does LOV query get executed if there doesn't exist any entity instance to back up the source ViewObject? The scenario usually arises if you have LOV defined for an attribute, which is part of query panel. This article discusses this specific scenario with a use case. Use case Let us take the classical Employee entity as example. This 'Employee' is based on HR schema . The detailed entity is shown below. You can see that each Employee falls under specific Department and Manager. This means that while defining a new Employee record, it's required to associate an existing Employee as manager to the new record. To improve the usability, let us define a LOV against manager attribute in Employee ViewObject. Let us make this LOV much smarter by adding an additional requirement to filter down the values of ‘Manager LOV’ based on logged in user's Department Id. So 'Manager LOV' should display only those Employees who belong to the same Department as ...

Programmatic PPR on af:outputText / af:outputFormatted

Partial page rendering (PPR) allows small areas of a page to be refreshed without the need to redraw the entire page. I had a scenario where an af:outputText component needs to be refreshed programmatically. The <af:outputText> tag looks like as ashown below. <af:outputText id="op1" value="#{myBean.someValue}" /> To PPR the outputText component, tried calling the following API from backing bean method. AdfFacesContext.getCurrentInstance().addPartialTarget(outputTextComp); Unfortunately this didn't help me out. Also, noticed the following warning message in the server console at runtime. oracle.adfinternal.view.faces.renderkit.rich.PprResponseWriter$PPRTag finish WARNING: no PPR-capable ID found for elements of: RichOutputText[UIXFacesBeanImpl, id=op1] Further investigation on the above issue revealed some interesting points. Let me try summarizing them below. Why does Programmatic PPR fail for <af:outputText>? In an attempt to reduce content...

Programmatically publishing Contextual Events

ADF task flows provide modularity to the web applications. Bounded task flows are really useful while realizing business use cases, which may repeats across application(s). Please refer Fusion Developer's Guide if you want to know more about this topic. Bounded task flows are added to the page as regions. It is very common that one region may need to communicate with other regions. This is accomplished by Contextual Events. To know more about Contextual Events, please refer Creating Contextual Events . There are scenarios where task flows may need to raise the Contextual Events based on complex business conditions. Declarative event handling mechanism might not be sufficient in this case. Now the question is how to raise 'Contextual Events' programmatically from backing bean? Let me try summarizing the steps below. Please refer the Fusion Developer's Guide for detailed explanation on creation of Contextual Event. 1. Create the Producer (Payload) Method 2. Bind the Prod...

Target Unreachable, identifier row resolved to null !

Image
SEVERE: Server Exception during PPR, #1 javax.el.PropertyNotFoundException: Target Unreachable, identifier 'row' resolved to null at com.sun.el.parser.AstValue.getTarget(AstValue.java:xx) at com.sun.el.parser.AstValue.isReadOnly(AstValue.java:xxx) at com.sun.el.ValueExpressionImpl.isReadOnly(ValueExpressionImpl.java:xxx) at Have you ever seen the above exception while running the web application built on ADF? Apparently, this exception doesn’t communicate much on the root cause and noticed that developers search in dark to find a solution. This article discusses couple of possible reasons for this error. Incorrect Key definition for ViewOject Consider the classic Employee - Department example. Below diagram shows the association between Employee and Department . Please note that Emp has Empno as Primary Key(PK) defined and Dept has Deptno as Primary Key. Let us try visualizing User Interface for Employee. An Employee can belong to a specific Department. So let us try de...

A detailed look at Binding Model Parameter Options (NDOption)

Image
ADF binding layer has been always a pleasant surprise for me. I have not seen such a 'rich glue layer' in any other frameworks. While wiring the business service methods with UI Components , developers can opt for specific 'Parameter Options' . These options would decide how the binding container should assign the value to the parameter(s) at runtime. This article discusses the significance of the Binding Model Parameters Options and their proper usage. Please note that Binding Model Parameters Option is termed as NDOption in your page definition file. Where can I see Binding Model Parameter Options? To answer this question let us start building an application and see where we really use this in real life. Follow the steps given below. 1. Here, I assume that you already have one Fusion Web Application in place, with Application Module defined. Please refer Fusion Developer's Guide for Oracle Application Development Framework in case you are not familiar with buildi...