January 22, 2013

Accessing Session Scope and Request Scope objects in ADF


We can access the session Scope objects in ADF by using ADFContext class.

The syntax for this is:

ADFContext.getCurrent().getSessionScope().get(obj);

Where obj is the object name configured in the session scope.

In the same way, we can also access the objects in request scope by using the below syntax:

ADFContext.getCurrent().getRequestScope().get(obj);

January 16, 2013

Fetching values of a list object of ADF bindings from Java


Before giving the solution, let me explain my scenario. I have JSF binding object “internalProfile” which is a list of a class. The definition of the object is like below.

List<KeyValue> internalProfile=new ArrayList<KeyValue>();

KeyValue is a bean with two String properties key and value.
A binding is created for the “internalProfile” and input fields are created for its values as below in JSF page.

//code in the JSF
<af:forEach items="#{bindings.internalProfile.rangeSet}" var="row" varStatus="sdiIndex">
<af:inputText value="#{row['value']}" label="#{row['key']}"                            id="it_${sdiIndex.index}"></af:inputText>
            </af:forEach>

We can see the bindings of the page below.





Now, I need to fetch all these text fields in my bean which is achieved by using the below code snippet.

BindingContainer bc =BindingContext.getCurrent().getCurrentBindingsEntry();
            oracle.adfinternal.view.faces.model.binding.FacesCtrlHierBinding list = (oracle.adfinternal.view.faces.model.binding.FacesCtrlHierBinding)bc.get(BINDING_INTERNAL_PROFILE);
            Row[] allRowsInRange = list.getAllRowsInRange();


January 9, 2013

Invoking Application Module from Java


Below code snippet will allow us to access the application module from java class.
In this code, I was trying to get records from the table.
For this, I have got the view object from the application module and applied a view criteria on the view object through which I got the records row.

/*Accessing Application Module*/
        AppModuleImpl appModule =
            (AppModuleImpl)ADFUtils.getApplicationModuleForDataControl("AppModuleDataControl");
/*Accessing View Object from App Module. Here, User_infoView is my own view created in App module*/
        ViewObjectImpl voImpl = appModule.getUser_infoView1();
        ViewCriteria vc = voImpl.createViewCriteria();
        ViewCriteriaRow vcRow = vc.createViewCriteriaRow();
        vcRow.setAttribute(“firstname”, "= 'anand'");
        vc.add(vcRow);
        voImpl.applyViewCriteria(vc);
        voImpl.executeQuery();
        System.out.println("Query: " + voImpl.getQuery());
        while (voImpl.hasNext()) {
            Row row = voImpl.next();
            String[] attributeNames = row.getAttributeNames();
            for (int index = 0; index < attributeNames.length; index++) {
                    System.out.println("Required: " +row.getAttribute(attributeNames[index]));
            }
        }

Invoking actions before loading the JSF or JSFF page

If we want to invoke the operations like Create or CreateInsert of a data control while loading the page, we can achieve this by doing below


  • Open JSF or JSFF page, go to bindings tab
  • In the “Executables”, click on “+” symbol to add, select InvokeActions options from the given list
  • Enter some ID to the action and select Binds from the given list
  • Select the action and click on pencil icon to edit it, “Common Properties” window will be opened
  • Go to common tab, select a value to Refresh (for example, every time when the JSF page is loaded, if the create action needs be executed then the refresh value should be “always”)
  • Give the Refresh Condition
  • Click on Finish
  • Move the action to the top of the “Executables” as shown in the below image


 

January 8, 2013

Assign DBSequence to a property in Entity Object

I want to add a sequence to the user_id field in user_info table of my database. For which I have followed the below procedure.
  • Create a db sequence named “userid”
Create sequence userid start with 10000000001

  • Open the Entity Attribute, “user_id” in the Entity Object of the application
  • Select Type as Integer and  click on Value type “Expression” radio button
  • Enter the below expression in the value field
 (new oracle.jbo.server.SequenceImpl("USERID",adf.object.getDBTransaction())).getSequenceNumber()

Where “USERID” is the sequence name which is created already
  • Click on Ok