Pages

Thursday, July 26, 2012

Accessing and Iterating HashMap Values

This post covers how to access value for a particular key in HashMap  and iterate over the HashMap.


First we will cover access value for a particular Key in HashMap : -

1. Create a HashMap in bean. Say we have changeMap in testMapBean.
2.  To Access value for key 'abc', use following expression #{pageFlowScope.testMapBean.changeMap.abc}

Simple !

Iterate Over values of HashMap : -

1. Create a HashMap in bean.
2. Create a method returning entrySet array for HashMap.
3. Bind iterator to entrySet returned and access each value using expression : #{row.value}

Sample application can be downloaded here ( HashMapAccessApp ).

Custom Operator ( IN operator ) In viewCritria at Design Time

There are a couple of post which explains how to apply IN operator where clause to viewobject. This post refer to already existing solution and new posted solution on case by case basis.  Here goes the different approaches  :

1. IN OPERATOR THROUGH CUSTOM VC -> When u have option to write a method, you can create and apply custom view criteria as described in here ( Use SQL subquery and SQL OPERATOR ( IN, BETWEEN) in ViewCriteria ).
2. IN OPERATOR IN VO QUERY -> When you have IN operator in query of viewobject and want to pass multiple values through that bind variable, you can use either of these approaches :
 a) Using Type and Cast : Example 126 from  Steve's Blog :-
  •       Create Type and DB function returning that type for comma separated list.
  •      Use type in query like
SELECT Departments.DEPARTMENT_ID,
Departments.DEPARTMENT_NAME,
FROM DEPARTMENTS Departments
WHERE DEPARTMENT_ID IN (
SELECT * FROM TABLE( 
CAST ( in_number_list(:CommaSeparatedListOfDeptId) 
as num_table)))
 b) Using regular expression : Passing comma separated string as bind variable for VO query's IN operator 
          WHERE Emp.ENAME in
                (select regexp_substr(:Bind_Ename_Comma_Sep_List,'[^,]+', 1, level)
                 from dual
                 connect by
                      regexp_substr(:Bind_Ename_Comma_Sep_List, '[^,]+', 1, level)
                          is not null)


 3. OVERRIDE getCriteriaItemClause METHOD FOR CUSTOM WHERE CLAUSE :
Using bind variable for the SQL statements with IN clause
Download the application from the link ( available at bottom of page) and look for Dept_OverriddenGetCriteriaItemClause_VOImpl.java .



4. USING CUSTOM IN OPERATOR IN VIEW CRITERIA AT DESIGN TIME :

At first create you design time viewcriteria. Regarding how to add custom operator you can refer to dev guide Section 31.3.3. Here goes the code snippet for CUSTOM_IN Operator.


NOTE : Default value for departmentIdVar is -1to avoid where clause i.e. DepartmentId IN ( null).



If you want to have some other kind of customized where clause that should be applied using custom operator, write a method in your VOImpl returning whereClause String and refer to it in your customOperator . For example : you want to apply where clause : -   Salary Between 2000 And 5000 the your customWhereClauseMethod should return String "Between 2000 And 5000".

return  adf.object.getViewCriteria().getViewObject().customWhereClauseMethod()

You can download the sample application from here ( CustomOperatorApp ) . Run the application module and try passing the comma separated values and it works.

Tuesday, July 24, 2012

XMLGregorianCalendar and Date conversions


Converting from oracle.jbo.domain.Date to java.util.Date to GregoriaCalendar to XMLGregorianCalendar


Tuesday, May 22, 2012

ManagedServer For ADF application Deployment

Here we will talk about how you can create a separate managed server for ADF applications deployment. The way you install SOA, Webcenter etc and create Managed Servers for deployment... same can be done for ADF applications as well.


Steps involved :
1. Install Weblogic Server - I will assume that you already have a weblogic server installed and will not cover in this post.

2. Install ADF runtime (available as part of Jdeveloper 11g) to WebLogic Server
Run the Jdev installer and select options as shown below.
Select to install in your existing middleware home where you have installed Weblogic






 CLICK NEXT AND Select ADF Runtime




Now do Next and Finish the wizard.

3. Run Config.cmd to create/extend domain.




Create or Extend the domain with ADF Runtime. You should see the option to select ADF Runtime as below.




 That is all .. you can go ahead with domain creation/extension as you do with SOA.
 
 
Enjoy.....

Friday, May 4, 2012

Using JSTL Functions in ADF Page

This post will illustrate how can we use the JSTL functions in you ADF Jspx/Jsff pages.

A friend came with following problem :

Attribute Value : +1100WWS displayed in a table column with some inlineStyle.
Same attribute value needs to be displayed in following manner
+ -> with a different inlineStyle
-> with another inlineStyle.

Business Service Layer used in his project EJB. If it would have been ADF BC, I would have recommended creating transient attribute and all. Now I don't have any idea on EJB, I started looking for something to do on expression Language on ADF page. Simple google Search - subString operation in Expression Language.

Answer is - Use JSTL.

How to use JSTL -
1. Add JSTL function in your tag library.






2. Include namespace in your jsff.



3. Use JSTL functions in your expression language.






Src: http://www.tutorialspoint.com/jsp/jsp_standard_tag_library.htm


Enjoy...


Friday, April 13, 2012

How to delete the domain from the weblogic

As we know there is no configuration wizard to delete the existing domains. So you can delete the domains using below mentioned manual steps :

I am going to delete the domain "mycustomdomain" -
1. Open the domain-registry under $Middleware_HOME directory. Remove the entry referring to mycustomdomain

Code Snippet in domain-registry.xml

<domain location="C:\Oracle\Middleware\user_projects\domains\mycustomdomain"/>

2. Open nodemanager.domains file under $Middleware_HOME\wlserver_10.3\common\nodemanager\ folder. Remove the corresponding entry referring to mycustomdomain.

Code Snipper in nodemanager.domains

mycustomdomain=C\:\\Oracle\\Middleware\\user_projects\\domains\mycustomdomain

3. Delete the domain folder under domains folder manually.

$Middleware_Home\user_projects\domains\mycustom_domain

4. Delete the domain folder under applications folder manually.

$Middleware_Home\user_projects\applications\\mycustom_domain

Printing a command link using af:showPrintablePageBehavior

This post will illustrate how you can print the text on CommandLink when using af:showPrintablePageBehavior tag

Problem :
By default, when showPrintablePageBehavior is used in page and it renders the page in print mode in new tab with exception that command link disappears in the printable version.
As per default print behavior of ADF that it omits command buttons, links etc present on the page.

Solution :
Add another component (e.g. af:outputText) next to the commandlink (together with the link) and set the rendered attribute to

rendered ="#{adfFacesContext.outputMode eq 'printable'}"


Then (in theory) the outputtext only gets rendered if you render the page as printable.

Enjoy...

Wednesday, April 4, 2012

Master Detail Form for creating master-detail records

This post will show you how to create master-detail form to create master-detail record.
You will find quite many blogs for below requirements :
Master Form and Detail Table -- Keep adding detail record a queried master.
Master Table and Detail Table -- Add master record and then add detail record.

Here fields from both master and detail table are taken in to same ADF form allowing you to create one Master and one Detail record.

I have referred Controlling Entity Posting Order to Avoid Constraint Violations from Oracle® Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework
11g Release 1 (11.1.1.6.0).


To start with you will be having entity, association, viewobject and viewlinks created on top of your database table. Once your VO's ( updatable based on entity Objects ) are created, you need understand how you want to populate your primary key Id attribute in Master and detail.

In my sample application, I have populated primary key for master and detail Entities like this :

adf.object.nextVal("DEPARTMENTS_SEQ")
adf.object.nextVal("LOCATIONS_SEQ")


Note that when you are using the above groovy, it means you need to have nextVal method in your EntityImpl. So add below method when using adf.object.nextVal("<sequenceName>").

    protected Number nextVal(String sequenceName) {
    SequenceImpl s = new SequenceImpl(sequenceName, getDBTransaction());
    return s.getSequenceNumber();
    }

This is all about setting primary key, where is the master detail form.

From Oracle Link Referred. { Default Post Processing Order :- By default, when you commit the transaction the entity objects in the pending changes list are processed in chronological order, in other words, the order in which the entities were added to the list. This means that, for example, if you create a new detail record and then a new master record related to that product, the new detail record will be inserted first and the new master record second. }

Since you will be calling a commit ( AMDataControl commit method ) from UI, we need to make sure that master gets committed before the detail row. There are couple of ways to do that which are mentioned in the Oracle Link referred.
One way is Compositions changing the default processing order.  -- Andrejus Blog explains this.
Other way is overriding postChanges() method to control Posting Order --- Used in this blog.

So here goes the code for DetailEOImpl where postChanges() method is overridden to make sure the master is committed first.

    public void postChanges(TransactionEvent e) {
      /* If current entity is new or modified */
      if (getPostState() == STATUS_NEW ||
          getPostState() == STATUS_MODIFIED) {
        /* Get the associated Locations for the Department */
          LocationsEOImpl location = (LocationsEOImpl)getLocationsEO();
       
        /* If there is an associated location */
        if (location != null) {
          /* And if it's post-status is NEW */
          if (location.getPostState() == STATUS_NEW) {
            /*
             * Post the location first, before posting this
             * entity by calling super below
             */
            location.postChanges(e);
          }
        }
      }
      System.out.println(" this.getLocationId()-"+this.getLocationId());
     
      super.postChanges(e);
    }


Now you are done, just create your ADF form and add commit to the button on Page. it works perfectly fine. In my application, I am calling a AM exposed method as default activity for the taskflow to create the master and detail row ready for entering values. Then added the commit button on page calling datacontrol commit method.


Notes : -  You might notice that I have not followed a few steps mentioned in the Oracle link referred. As per section 38.8.3 Overriding postChanges() to Control Post Order steps that needs to be followed are as below :
  1. 38.8.3.1 Observing the Post Ordering Problem First Hand  -- Describes about the problem of commit of master detail.
  2. 38.8.3.2 Forcing the Supplier to Post Before the Product -- This is what we have done by overriding the postChanges() method.
  3. 38.8.3.3 Understanding Associations Based on DBSequence-Valued Primary Keys  -- This explains what exactly happens when you use DBSequence-Valued Primary Keys. Have you noted that we are populating the primary key from from DBSequence, but ours is not DBSequence-Valued PrimaryKeys. So primary keys in our case gets assigned with proper values as soon as a row is created, where as in case of DBSequence-Valued Primary Keys it is a negative number.
  4. 38.8.3.4 Refreshing References to DBSequence-Assigned Foreign Keys - We don't need this because we don't have DBSequence-Valued Primary keys.

Sample application can be downloaded from here.

Monday, March 26, 2012

PageFlowScope with Unbounded Task Flows

Well I am not explaining any memory scopes here. I was going through blogs and found this one pretty interesting.
Chris Muir has explained it pretty well here
http://one-size-doesnt-fit-all.blogspot.in/2011/10/pageflowscope-with-unbounded-task-flows.html