Friday, October 11, 2013

How to preserve the user session data during activation and passivation of application module in Oracle ADF?

User session specific information, like a queried user name or account data, can be saved in the Oracle ADF Business Components session using a call to getUserData() that returns a java.util.HashMap as a data store.

The user data map can be accessed from Java can be obtained from the user session using the below method call

getDBTransaction().getSession().getUserData()

However, the user specific information in the userData HashMap is not persisted by default when activation / passivation occurs for application modules that have Application Module pooling enabled, which means that custom session data may be lost between requests.

What we need to to is to passivate the session user data together with the other state data stored by the framework and load it back when the AM is requested the next time (when it gets activated again). To do this we have to overwrite the following two methods in the AMImpl class of ADF application module.

@Override protected void activateState(Element aElement) { super.activateState(aElement); if (true) { Hashtable lData = getSession().getUserData(); if (aElement != null) { // 1. Search the element for any <PrivData> elements NodeList nl = aElement.getElementsByTagName(PRIVATEDATA); if (nl != null) { // 2. If any found, loop over the nodes found for (int i = 0, length = nl.getLength(); i < length; i++) { // 3. Get first child node of the <PrivData> element Node child = nl.item(i).getFirstChild(); if (child != null) { // 4. Set the data value to the user data hashmap String lDataString = child.getNodeValue(); String[] lSplitkeyval = lDataString.split(";"); for (int ii = 0; ii < lSplitkeyval.length; ii++) { mLogger.fine("..." + lSplitkeyval[ii]); String[] lSplit = lSplitkeyval[ii].split("="); lData.put(lSplit[0], lSplit[1]); } break; } } } } } }

@Override
protected void passivateState(Document aDocument, Element aElement) {
super.passivateState(aDocument, aElement); if (true) { // 1. Retrieve the value of the user data to save and build a string representation Session lSession = getSession(); Hashtable lData = lSession.getUserData(); String lDataString = ""; Set<String> keyset = lData.keySet(); if (!keyset.isEmpty()) { Iterator<String> keys = keyset.iterator(); while (keys.hasNext()) { String key = keys.next(); mLogger.fine("..." + key + "=" + lData.get(key)); lDataString += key + "=" + lData.get(key) + ";"; } } // 2. Create an XML element to contain the value Node node = aDocument.createElement(PRIVATEDATA); // 3. Create an XML text node to represent the value Node cNode = aDocument.createTextNode(lDataString); // 4. Append the text node as a child of the element node.appendChild(cNode); // 5. Append the element to the parent element passed in aElement.appendChild(node); } }

Tuesday, October 1, 2013

How to call the valueChangeListener of af:inputText from the java script in Oracle ADF?

Step1

Let us say our value change listener is as follows

import javax.faces.context.FacesContext;
import javax.faces.application.FacesMessage;

public void onChangeCompanyName(ValueChangeEvent valueChangeEvent) {
    FacesMessage msg = new FacesMessage("In the value change listener of company");
    FacesContext context = FacesContext.getCurrentInstance();
    context.addMessage(null, msg);
}


Step2

Our javascript should be

function callValueChangeEvent(evt) {
      //Method to get component using id (here inputText)
      var field = AdfPage.PAGE.findComponentByAbsoluteId('it1');

      //Change(set) field's value
      field.setValue('I am JavaScript text');

      //Get New changed value
      var newVal = field.getValue();

      //Queue ValueChangeEvent (component,oldValue,newValue,autoSubmit)
      AdfValueChangeEvent.queue(field, null, newVal, false);
}

Friday, June 28, 2013

Implement Primary Key Population for ADF BC based on SQL server

We can auto populate the primary key attribute in many ways for an ADF BC Entity Object based on Oracle Database but for the Entity Objects generated using SQL Server the following proceedure should be used

Step 1. Create an auxiliary database table
Create an auxiliary database table that will be used to generate the primary key values as shown below.

CREATE TABLE [dbo].[S_ROW_ID](
[start_id] [numeric](38, 0) NULL,
[next_id] [numeric](38, 0) NULL,
[MAX_ID] [numeric](38, 0) NULL,
[AUX_START_ID] [numeric](38, 0) NULL,
[AUX_MAX_ID] [numeric](38, 0) NULL
)

Step 2. Create the database Connection 
ROWIDAM_DB
In your application, create a database connection named ROWIDAM_DB that points to the database containing your S_ROW_ID table.
Note: It is mandatory to use the same connection name

Step 3. Configure the Primary Key Attributes 
Set the primary key attribute value to oracle.jbo.server.uniqueid.UniqueIdHelper.getNextId() in the Entity Object as shown below



Step 4. Modify the adf-config.xml
Though we create the connection to the sql server, we need to modify the default preferences in adf-config.xml as shown below.