Sunday, December 26, 2010

TestCase: Programmatically Navigating in Parent TaskFlow based on outcome of another Taskflow in popup.

This blog contains the test case for the solution of previous blog Programmatically Navigating in Parent TaskFlow based on outcome of another Taskflow in popup.

Testcase:
I have a parent taskflow (say PTF) having a jsff page (say ParentPage) and you can navigate to two other pages Outcome1 and Outcome2 as shown below:


Decision to navigate to either Outcome1 or Outcome2 is based on the return activity of another Taskflow (say CTF2) which is dropped as region in dialog of popup on ParentPage. Since CTF is dropped as a region inside popup we would have to programmatically navigate on parent taskflow(PTF). Also since there could be more than one return activity in CTF to exit taskflow, its just not enough to know that takflow is ended. We also need to know so that we could appropriately take decision. Here are the two outcome of the child taskflow.


As you can see in the child taskflow (CTF) there are two return activities namely ReturnActivity1 and ReturnActivity2. Now lets go the solution.

As a first approach to the solution create a return taskflow parameter for the child taskflow (CTF) as shown and set the value to a pageFlowScope value.


Within the Child taskflow make sure the value of the pageFlowScope parameter is set to correct return activity before the taskflow return activity executes. This could be done either by method call activity return the taskflow return value and setting it to pageFlowScope.


Or by dropping setActionListener on the button/menu that leads to the return activity and set the pageFlowScope on it. On a bean create a method that would act as a finalizer for CTF to capture the value in a variable.

    public String ReturnActivityValue = null;

    public void finalizerForCTF(){
        Map taskFlowReturnParameters = getCurrentTaskFlowReturnParameters();
        ReturnActivityValue = getReturnActivityValue(taskFlowReturnParameters);
     }
    public static TaskFlowId getTaskFlowId() {
        ControllerContext controllerContext = ControllerContext.getInstance();
        ViewPortContext currentViewPort = controllerContext.getCurrentViewPort();
        TaskFlowContext taskFlowContext = currentViewPort.getTaskFlowContext();
        TaskFlowId taskFlowId = taskFlowContext.getTaskFlowId();
        return taskFlowId;
      }   
     public static Map getCurrentTaskFlowReturnParameters() { 
         return getReturnParameters(getTaskFlowId()); 
     }                     
     public static Map getReturnParameters(TaskFlowId taskFlowId) { 
         assert taskFlowId != null;      
         TaskFlowDefinition taskFlowDefinition = getTaskFlowDefinition(taskFlowId); 
         Map namedParameters = taskFlowDefinition.getReturnValues(); 
         return namedParameters; 
       }    
     public static TaskFlowDefinition getTaskFlowDefinition(TaskFlowId taskFlowId) { 
         assert taskFlowId != null;        
         MetadataService metadataService = MetadataService.getInstance(); 
         TaskFlowDefinition taskFlowDefinition = metadataService.getTaskFlowDefinition(taskFlowId); 
         return taskFlowDefinition; 
       }  
   
     public String getReturnActivityValue(Map btfParameters) { 
         HashMap taskFlowParameterValues = new HashMap(); 
         FacesContext facesContext = FacesContext.getCurrentInstance(); 
         Application application = facesContext.getApplication(); 
         AdfFacesContext adfFacesContext = AdfFacesContext.getCurrentInstance(); 
         Map pageFlowScope = adfFacesContext.getPageFlowScope();
         String returnValue = null;
        
         for (Object parameter : btfParameters.values()) { 
           NamedParameter namedParameter = (NamedParameter)parameter; 
           String parameterName = namedParameter.getName(); 
           String parameterExpression = namedParameter.getValueExpression(); 
           Object parameterValue; 
           String stringValue;         
        
           if (parameterExpression == null) { 
             parameterValue = pageFlowScope.get(parameterName); 
           } else { 
             parameterValue = application.evaluateExpressionGet(facesContext, parameterExpression, Object.class); 
           } 
        
           if (parameterValue != null) { 
             try { 
               stringValue = parameterValue.toString(); 
             } catch (Exception e) { 
               stringValue = ""; 
             } 
           } else { 
             stringValue = ""; 
           }
             if("ReturnActivityValue".equalsIgnoreCase(parameterName)){
                 returnValue = stringValue;
             }           
         } 
         return returnValue;
       }


Associate finalizerForCTF() with the CTF takflow as below:



Create a method in bean to associate with the region of CTF taskflow. Here is how method looks:

    private static final String Exit1Value = "RA1";
    private static final String Exit2Value = "RA2";
        public void regionNavationListener(RegionNavigationEvent regionNavigationEvent) {
        if(regionNavigationEvent.getNewViewId() == null && ReturnActivityValue != null){
            if(Exit1Value.equalsIgnoreCase(ReturnActivityValue)){
                navigate("outcome1");
            }else if(Exit2Value.equalsIgnoreCase(ReturnActivityValue)){
                navigate("outcome2");
            }
        }
       
    }
    public void navigate(String controlFlowCase){
        NavigationHandler nvHndlr  =
        FacesContext.getCurrentInstance().getApplication().getNavigationHandler();
        nvHndlr .handleNavigation(FacesContext.getCurrentInstance(), null,
        controlFlowCase);
    }

Associate the method with region navigation listener.

Programmatically Navigating in Parent TaskFlow based on outcome of another Taskflow in popup.

In this article I will to show how can we navigate in parent taskflow based on outcome of another taskflow on the parent page dropped as a region or is being used in a popup. It seems that currently we do not have any public API’s to get these details from the Taskflow. However the good news is an ER 10198616 has been logged by Frank Nimphius to request public API’s for them.

Credit for the solution below goes to Chris Muir and Frank Nimphius for showing me way that led to this solution through thread posted in Oracle forum. Also code to access the taskflow API’s were taken from the blog  JDev: Programmatically capturing task flow parameters.

Issue at hand:
From a parent page a popup is launched that contains a taskflow which contained various ReturnActivity with different outcome. Based on what the outcome value of return activity a navigation in parent taskflow needs to be activated.

Solution:
We could achieve above by:
1. Storing the Taskflow Return Value in a Taskflow Return Parameter.
2. Programmatically capturing the Taskflow Return Parameter value in bean through Taskflow finalizer.
3. In RegionNavigationListener, based on the value captured in step 2, navigate to appropriate view or Taskflow.

To get the closer look you can check post TestCase: Programmatically Navigating in Parent TaskFlow based on outcome of another Taskflow in popup.

How to navigate programmatically using ControlFlow Case.

There are times when we wish to navigate from code instead of using the ‘Action’ property of UI component and at same time we like to use the ControlFlow cases defined in the taskflow. Well if you wish to do that you can use handleNavigation method from NavigationHandler class in javax.faces.application package.

Here is the sample:
            NavigationHandler  nvHndlr = FacesContext.getCurrentInstance().getApplication().getNavigationHandler();
            nvHndlr.handleNavigation(FacesContext.getCurrentInstance(), null, "PROVIDE_CONTROL_FLOW_CASE_NAME");

Tuesday, November 23, 2010

Using Bar Graph (Oracle DVT Component): Part II

This blog is continuation of my previous blog Using Bar Graph (Oracle DVT Component): Part I which showed how could we easily use one of the Data Visualization Tool Bar Graph. I will further try to show the ease with which these component can be used to create a varied graph.

Variation I:

In graph we took the example of Salary versus employees. Lets go ahead and extend the same example to add commission to the graph to show something like:


In the graph above red bar displays the commission too along with this. To achieve we can add one more attribute to the View Object acting as the source for this graph and sql for the vo could look like this:
      Select Ename, Sal, comm from EMP

Now we can either edit the Map binding on the page binding to add the commission attribute (comm in this case) to the Bars column or you can delete the old map and drag and drop the view object from data control as Graph (steps are same as mention in the Part I of this blog except addition of commission attribute as shown below).


Variation II:


In the above graph Salary and commission are shown as two seperate bars we can combine them in one bar as below:


To achieve this just select Stacked Bar as the Graph Type and rest remains the same:



So convenient... right?

Using Bar Graph (Oracle DVT Component): Part I

In this blog I would try to show how you can play around with one of the Oracle ADF’s Data Visualization Tool (DVT) Bar Graph. Initially it seems so tough to come up with a graph component and ofcourse making it dynamic so that it displays graph based on current data. [I would be using default HR schema from the Oracle Database.]

1.    Let’s start with creating a Model and ViewController project.
2.    In your model project we would be creating View Object’s (either an Entity Based or SQL based, since we may not be updating the data through graphs a SQL based View Object could be efficient) which would be acting as source for the graphs.  I would be creating SQL based View Object in this entire demo.
3.    Create an Application module with name say ‘AppModule’, this would be used to expose all the view objects to client as Data Control.
4.    Right Click on the ViewController project and click ‘New’. In the New Gallery dialog, select ‘JSF’ under Categories and then select JSF Page under items and click ok.
5.    In Create JSF Page dialog, provide a file name ‘DemoDVT1’, make sure ‘Create as XML Document  (*.jspx)’ is checked and click ok.

        Graph 1: Salary Vs Employee

6.    Create a View Object with the SQL and name it as SalaryVsEmployeeVO.
        Select Ename, Sal from EMP
7.    Add this VO to Application Module AppModule.      
8.    Drag the SalaryVsEmployeeVO from the DataControl and drop to the jspx DemoDVT1 as Graph.


9.    In Component Gallery for the graphs, select ‘Bar’ as Categories for Bar Graph, select Graph Type and a Quick Start Layout and click OK.


10.    In Create Bar Graph wizard drag and drop ‘Sal’ into the Bars input box. You can also select the same from the green ‘+’ sign. Also drag ename column into the X axis input box.


11.    Optionally you can click on the Preview Tab to see how the outcome will look like.
12.    Once done just run the DemoDVT1.jspx page to see the graph which would look similar to one below (there could be some difference based on the data in the EMP table).


13.    This is how you can proceed with working with Bar graph in Oracle ADF.
   
I will continue further on the use of Bar Graph in next part.

Sunday, November 21, 2010

Using Oracle Identity Manager’s Java API's from oimclient.jar

Lately I got chance to work on Oracle Identity Manager and I was trying to access Oracle Identity Manager through Java API’s exposed by this product.  Ofcourse it’s a great product but at same time it too complicated and I guess experts would agree that it’s so easy for a newbie to get lost in the tons and tons of doc even if complexity is put aside. Well I was lost for sure…

Here is the link for the Oracle's Developer Guide for Oracle Identity Manager if you want to go for detail steps and demo code.

Here I will try to put some steps in simple and straight forward way if you are interested to access OIM’s Java API’s.

There are two entry points for the OIM, one through OIMClient and other through tcUtilityFactory. Well I cannot comment which is the better but from the Doc OIMClient is ofcourse recommended one. One other thing is coming from the Oracle’s Application Development Framework (ADF), I selected JDeveloper as my tool.
  1. Copy oimclient.zip from OIM Server (OIM_ORACLE_HOME/server/client/ oimclient.zip) to local drive.
  2. Create a Fusion Web Application using JDeveloper.
  3. In the model project go the project properties select Run/Debug/Profile, click Default under Run Configurations and click edit.
  4. Go to the project folder in your JDeveloper Workspace and create two folders as jlib and conf.
  5. Extract the oimclient.jar to any folder and copy all the jars(OimClient.jar, Commons-logging.jar, Eclipselink.jar and Spring.jar) from it to jlib folder that we created in step 4.
  6. Copy the authwl.conf file to conf folder created in step 4.
  7. Go to the project properties for the model project and click on Libraries and Classpath. Click on Add JAR/Directory and add following jars OimClient.jar, Commons-logging.jar, Eclipselink.jar and Spring.jar
  8. Set the Java Options to
    -DXL.HomeDir=PATH\OIM
    -Djava.security.auth.login.config=FILE_PATH\conf\authwl.conf
  9.  Now it’s time to test the API. Create a sample java class and add following method to it.

        public static OIMClient client;
        private static String OIMUserName = "USERNAME";
        private static String OIMPassword = "PASSWORD";
        private static String OIMURL = "t3://OIM_HOSTNAME:OIM_PORT";
        private static String OIMInitialContextFactory = "weblogic.jndi.WLInitialContextFactory";

        public static void loginWithCustomEnv() throws LoginException {
           Hashtable env = new Hashtable();
           env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, OIMInitialContextFactory);
           env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, OIMURL);
           client = new OIMClient(env);
           client.login(OIMUserName, OIMPassword);
           }

        public static void main(String args[]) {
            try {
                loginWithCustomEnv();
            } catch (LoginException e) {
                e.printStackTrace();
            }
        }
  10. Right Click and run to test the login.
Now you are ready to extend this to any level you want to take to. By the way oimclient.jar comes with the sample code to test the login and create user.

Saturday, November 20, 2010

OIM Error - java.lang.SecurityException Unable to locate a login configuration

While working with one of the ADF custom application and trying to integrate with Oracle Identity Manager (OIM) using the exposed Java API's from oimclient.jar, I was stuck with below error: 

Exception in thread "main" java.lang.SecurityException: Unable to locate a login configuration
at com.sun.security.auth.login.ConfigFile.(ConfigFile.java:93)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at javax.security.auth.login.Configuration$3.run(Configuration.java:246)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.login.Configuration.getConfiguration(Configuration.java:241)
at javax.security.auth.login.LoginContext$1.run(LoginContext.java:237)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.login.LoginContext.init(LoginContext.java:234)
at javax.security.auth.login.LoginContext.(LoginContext.java:403)
at Thor.API.Security.LoginHandler.weblogicLoginHandler.login(weblogicLoginHandler.java:58)
at oracle.iam.platform.OIMClient.login(OIMClient.java:134)
at oracle.iam.platform.OIMClient.login(OIMClient.java:114)
at model.SampleOIMClient.loginWithCustomEnv(SampleOIMClient.java:91)
at model.SampleOIMClient.main(SampleOIMClient.java:155)
Caused by: java.io.IOException: Unable to locate a login configuration


as the error seems pretty obvious, it took more than good time to get through a solution.

To get through this error we need to do setting for config file. When using Java API's from oimclient.jar, program looks for  authwl.conf and this is what needs to be set as Java Options.

-Djava.security.auth.login.config=FILE_PATH\conf\authwl.conf

If you are using JDeveloper here is how you can set the same:
Go to the project properties and select Run/Debug/Profile




Select 'Default' under Run Configuration and click on Edit. Enter the property as Java Options and click ok.




Once done.. you are good to go..

Wednesday, November 10, 2010

Fix for another Auto Suggest Bug .. Suggestion List wipes out the validation

This blog is again to complete my previous blog 'Another Auto Suggest Bug .. Suggestion List wipes out the validation' which points to a bug in functionality of Auto Suggest behavior.
Well Thanks to Oracle, they have fixed the bug but it would be released in Jdev version 11.1.2.0.0.

Monday, November 8, 2010

How to clear Weblogic Cache?

Recently while working with the customization of skin in Oracle Identity Manager(OIM) application I was required to restart the Weblogic server hosting OIM so many times and many a times I found that just bouncing/ restarting server is not enough, we will also need to clean up the cache so that new changes takes effect. Well, I am not a  Weblogic champion as of now, so I went on to google the thing up.. but it took me some time to really figure what to do.. so here is what you need to do in short:

1. Shut down Server.
2. Delete the contents of the folder ORACLE_HOME/user_projects/domains/your_domain/servers/your_server/tmp
You can also delete ORACLE_HOME/user_projects/domains/your_domain/servers/your_server/cache (optional)
3. Restart Server.

Friday, October 22, 2010

Fix for Auto Suggest Bug - Suggestion list renders even when focus is shifted from the field would be available in Jdev 11.1.2.0.0

Well this post is to complete my earlier post regarding the Auto Suggest functionality. To brief post was related to Auto Suggest Bug - Suggestion list renders even when focus is shifted from the field. Bug has been fixed but would be available in Jdev version 11.1.2.0.0. As of today's date its not back ported or should i say I just couldn't convinced Oracle to do so.

Wednesday, August 25, 2010

Test Case : Passing Parameters to Bounded Taskflows using Oracle Dynamic Tab Template

Recently I posted a blog showing what we need to do in addition to the existing code to pass parameters to bounded taskflow in Oracle's Dynamic Tab Template, but from few comments that I received it seems that there are still certain doubts or issue in order to get it working. So here is the test case that explains the stuff.

Test Case:
My test case is very simple, I have a jspx page with Dynamic Tabs Template. It has a link on the navigation area, clicking the link launches a popup that takes two input values. On click of 'OK' it launches the taskflow and passes the input values as taskflow parameter, which is displayed inside the taskflow on a page. Here is the screenshot:



As I said in previous blog we do need to download latest jar for this template which has these functionality added. Download the oracle-page-templates-ext.jar from here Or go to JDeveloper Help -- check for updates. On check for updates wizard, source step (step 2), check 'Official Oracle Extensions and Updates' and click next.


 Scroll to find 'Oracle Dynamic Tabs Page Template 1.02', check the option and click on finish to install the extension.


If you have downloaded the jar from my link you need to go to folder where Jdeveloper is installed ......\Middleware\jdeveloper\adfv\jlib. Rename the existing oracle-page-templates-ext.jar to oracle-page-templates-ext.jar.backup. Pasted the jar you just downloaded. If you have downloaded if from 'Check for Updates' then you don't need anything to worry about. Once you have installed the required template, we can go on creating the test case.

For test case, create a new jspx page with using Oracle Dynamic Tab Shell as page Template. Expand the page implementation detail and select radio button for 'Automatically Expose UI components in a New Manage Bean' and provide the details for Name, Class and Package.


Now create a taskflow that needs two taskflow parameters as follows:


Now create a jsff page and drop two input text fields on them. Set there values as value of input parameters, here is the code for the page:


Drop this page on the taskflow and set it as default activity.


Now lets bind the taskflow to the UI shell. Go to UI shell and on the navigation facet drop a popup with Dialog that takes two input text parameter. Also drag and drop a command link and drop an showPopupBehavior that would be used to launch the popup. Here is how it looks into structure window:

Also here is the how source looks like:


Once we launch the popup and get the input parameter, we will need to pass it too the bounded taskflow that we wanted to do and launch the taskflow itself.

Associate dialogListener method with the dialog listener property of the dialog which would look like       dialogListener="#{backingBeanScope.RunMeBackBean.dialogListener}", we can already see this in the code for jspx page above. One thing that we need to notice is the path of the taskflow passed. It should always be in pattern "/WEB-INF//<>TaskflowName>.xml#"

You can also download a test case here.

Thursday, August 19, 2010

UI Shell Dynamic Tab: Suppressing required / mandatory field error when navigating between Tabs or creating new Tabs.

Recently I have seen few posts in forum on how to suppress the mandatory / required validation error on attributes so that user can navigate between the tabs, can create new tabs when existing tabs has required or mandatory errors. I tried a test case and it could be downloaded here. In this blog I will try to detail the test case performed.

I created a test application that looks like the image below. Idea is to have two navigation links on the left which would launch their separate taskflow. Everytime I click on it should launch the taskflow in new tab no matter if their are incomplete tabs with missing required values. I should be able to navigate between the open tabs, work on them in any order I want, commit them or rollback them or even reset the inputs I have entered.

I created a new Jspx page with Oracle Dynamic Tab Shell template. On the Navigation facet I dropped two af:commandLink, set their immediate property to true and associated their action property with bean methods. Code that goes in backing bean is shown later. Here is how code in navigation facet looks like:


I created two jsff pages Page1 and Page2 and dropped view object from data control on to this page as editable form (for model, I used Employees tables provided by HR schema in Oracle database. I created an EO, VO and AM for this table). I also dragged Commit and Rollback from the data control and dropped on each page. Additionally I added a command button and inserted an af:resetActionListener to it.




I created 2 Taskflows, TF1 and TF2 and in their Overview tab set their behavior for their transaction as 'Always Begin New Transaction' and unchecked 'Share data control with calling task flow. Dragged and dropped CreateInsert method as default activity in both the task flows which leads to Page1 and Page2 in Taskflow1 and Taskflow2 respectively.  Here are how they look like:




Now in the backing bean of my Jspx page, I have below code:



Just doing so, we can close the tab using the close icon located in the end of the tab even when there are required attribute validation error's on the existing tab, we can reset the errors and values entered on the form using reset button, we can navigate between all the open tabs even with the existing error for required attribute or can open new tab. Have Fun !!

Tuesday, August 17, 2010

Passing Parameter to Bounded TaskFlows in UI Shell Dynamic Tabs

Passing parameters to UI shell was one of the genuine requirements and was resolved with some great works by ADF Experts like Richard, Pino, Steve, Chris. There is long history in the development of its solution which could be found in Oracle Forum for ADF UI Patterns & Best Practices.
Initially to get this working we had to customize oracle-page-templates-ext.jar and as far as I know Pino came up with very good blog ADF UI Shell: Extending the UI Shell to Allow Passing of Parameters to Bounded Task Flows that describes this in very detailed steps. Later Oracle logged the bug for this issue and solution was released as an extension as Oracle Dynamic Tab Template.
But now since solution is released we don't need to do any customization and in this blog I would be showing how to achieve this without going through all the pain :)

Before you start, download the latest 'oracle-page-templates-ext.jar' from OTN if you have not already done so. As said before it is available as an extension, so to get this, you can open JDeveloper go to Help - Check for updates.. and install Oracle Dynamic Tab Template'.

From the bean where you are trying to launch the dynamic tab add below code:

Map parameterMap = new HashMap();
parameterMap.put("",  );

parameterMap.put("",  );
........
// use over loaded _launchActivity method to launch taskflow as dynamic tab.
_launchActivity( "Tab Title" , "TaskFlow with path", false, parameterMap);

that's all needed to be done .....

Recently I found there are still some issues while implementing this.. so I created a blog 'Test Case : Passing Parameters to Bounded Taskflows using Oracle Dynamic Tab Template' detailing all the steps for this and also providing link for a sample test case.

Sunday, August 15, 2010

Working with af:inputDate in Bean

af:inputDate component register itself as instance of oracle.adf.RichInputDate class and its value attribute accepts java.util.Date type. Details of this component could be obtained at TagDoc.

Date (java.util.Date) itself does not have format, we format its value when we do need to print it. In order to format it in UI you could use af:convertDateTime but if you are thinking how can we do that in bean then here is a sample. Have a method something like below for the value change listener:

    public void valuechangelstnr(ValueChangeEvent vce){
        java.util.Date dateVal = (java.util.Date)vce.getNewValue();
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
        String datetime = dateFormat.format(dateVal);
        System.out.println("Date Time: " + datetime);
    }

In case you want to set a string value to java.util.Date.. here is the sample:

DateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd");
java.util.Date date = new java.util.Date ();
String dateStr = dateFormat.format (date);
try{
Date date2 = dateFormat.parse (dateStr);
}catch(ParseException pe){
      // do something
}

Friday, August 13, 2010

Printing an XMLElement to console

Debugging issues related to XMLElements sometimes get tougher as its get hard to know the structure of the data in the instantiated object. Here is the method that could be used to print the data of the XMLElement to console.

Instantiating XSLStylesheet object from XSL file.

As we know that ViewObjects can generate and consume XML using method like readXML(Element,int.XSLStylesheet) and writeXML(int,Long, XSLStylesheet). When dealing with XML and View Objects we could use stylesheets to control the format of the XML produced and consumed. In this post I provide an example how to get an instance of stylesheet file to that it can be consumed in ViewObject.

In order to get an instance of XSLStylesheet, create an stylesheet and add it to the project as resource. To do this go to project properties --> Project Source Paths --> Resource. Now add the XSL file to the include list. Doing so makes sure that file will be included when creating a war file for this application.




Now we can instantiate the an object of XSLStylesheet using this files as below:

Making a PLSQL call from AMImpl

Although there are various ways in which you can avoid making a PLSQL call in ADF but when working with legacy system we may need to call a procedure or function from ADF. In this post I am providing a sample method that shows how can we achieve it. Here we are trying to make a call to plsql method 'getEmployeeID' that returns employee number as string based on first name and last name.

 

Tuesday, August 10, 2010

How to Read resouce bundle values in Managed bean

Resource Bundle could be read in managed bean as below

String BUNDLE_NAME = "path.filename";
ResourceBundle rsBundle = BundleFactory.getBundle(BUNDLE_NAME);
String viewText  = rsBundle .getString("Text_Code");


I read in couple of Oracle forums that developers foound issue when they deploy this to standalone weblogic server. If its not working for you on standalone WLS server check if configurations are correct for resource bundle at Project Properties --> Resource Bundle.

How to default data on search criteria.

If we need to default data on search criteria item, we could do so while creating view criteria for eg.

So at runtime before  the query panel renders a search would be made with this default values. Please note that when you reset the values using reset button, it will set the values to the default provided while creating view criteria. At runtime it looks this:

Another Auto Suggest Bug .. Suggestion List wipes out the validation

In my last post about Auto Suggest I was talking about the bugs this behavior has. Found a new bug with this behavior and unfortunately this seems to be more concerning that the one posted before. Here goes the scenario.

In an input text field with the AutoSuggestBehavior enabled and has attribute level validation defined in entity, if building the list takes too long and user enters an invalis value and tabs out of the current field, the validation error is generated but it is then wiped out when the list is displayed.

I logged a Bug 9882151 against Oracle. Good part is, bug has been accepted but development has given it priority 3, which would mean that it may take quite some time for the fix to get released.

Auto Suggest Bug .. Suggestion list renders even when focus is shifted from the field

Auto-suggest is one of the very powerful feature/behavior provided by Oracle ADF and especially when usability is one of the focus. There are so many documents provided that describes the use of Auto-Suggest behavior. One very good article is written by Juan which is available at OTN.

Well, having said that.. there are few bugs too that goes with this feature. One such bug is rendering of the Auto-Suggest list even when we tab out of the field. This came up when I was working on this behavior in one of my previous projects. I reported this to Oracle (Bug 9840607) and good news which I lately found that this should be fixed in the latest version of JDevelper (JDEVADF_MAIN_GENERIC_100721.0058.5748).

Tuesday, June 29, 2010

Populating primary keys with DBSequence

There could be may scenarios where we would need to populate primary keys with DBSequence. If this is the
requirement then best place to populate them would be initDefaults() method of EOImpl.java
Open the EOImpl.java file and overwrite initDefaults() as shown in sample code :

@Override
protected void initDefaults()
{
  super.initDefaults();
  SequenceImpl seq = new SequenceImpl("SEQ_NAME", getDBTransaction());
  populateAttributeAsChanged(CONTRACTID, seq.getSequenceNumber());
}

CONTRACTID is the name of the attribute identifier and  SEQ_NAME is the name of the Sequence.

Monday, June 28, 2010

Opening PDF, TXT or DOC Files in ADF.

Opening .pdf, .txt and .doc/.docx file in application is very common requirement. In ADF this could be achieved very easily by af:goLink component. Here is the code snippet for the same:









important part here the location of these files. This files should be located inside public_html folder of your View Controller project.

Wednesday, June 2, 2010

Creating a Java Web Service using JDeveloper

Creating and testing Java Web Services could really be simple using JDeveloper. Let’s see how can we create a java service and test it in JDeveloper.

1. Create a project and Java class.
In Jdeveloper, click on File->New and choose General->Application in categories column. Select Generic Application and click Ok. Provide Application Name and Project Name in wizard and click ok.
Right-click on the project in Application Navigator and select New from context menu. In New Gallary window, select General->Java under Categories and then select 'Java Class' in Items section and click ok. In Create Java Class wizard, give a suitable name to class and set other properties as needed and click ok.
2. Add methods that need to be exposed as service


3. Create web service from the java class.
    Right click on the class and choose 'Create Web Service'. Rest follow the wizard for the completion. If you are not looking for any specific configuration, you can keep all the default setting in wizard. When wizard end's your service is ready to be deployed.
    Please note annotation @WebService at the start of the class, this is what makes this class to be recognized as web services.
Test your service.
    Right click on the java class and choose Test Web Service option from the context menu. This will deploy the service to Integrated Weblogic Server. Jdeveloper by default provides an interface (HTTP Analyzer) that could not only be used to provide input and receive output but we could also view WSDL, SOAP and HTTP messages.



Really simple, isin't ?

Code Ninja Chronicles - Oracle ADF

Does Oracle ADF rocks? Well at presents it is a debatable issue and which ever side you end up, I guess we all agree that every framework and or technology has its bright and dark side. However Oracle's turning each possible stone to get ADF to its pinnacle.

Here are couple of videos to enjoy:





If you want to be one of the code ninjas using ADF, this is were you can start.

Tuesday, June 1, 2010

Error: Unable to create JAXBContext

Well, few weeks back I was experimenting if I could create a java web service having a method that excepts XMLDocument or XMLElement as argument or probably return the same. While trying to expose this java class as services I constantly hit error:


javax.xml.ws.WebServiceException: Unable to create JAXBContext
at com.sun.xml.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:158)

................
Caused By: java.security.PrivilegedActionException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
oracle.xml.scalable.InfosetReader is an interface, and JAXB can't handle interfaces.
...............
Caused By: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
oracle.xml.scalable.InfosetReader is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
at oracle.xml.scalable.InfosetReader
at public oracle.xml.scalable.InfosetReader oracle.xml.parser.v2.XMLDocument.getInfosetReader()
at oracle.xml.parser.v2.XMLDocument
at public oracle.xml.parser.v2.XMLDocument testws.jaxws.TestXML.arg0
at testws.jaxws.TestXML
oracle.xml.scalable.InfosetReader does not have a no-arg default constructor.
this problem is related to the following location:
at oracle.xml.scalable.InfosetReader
at public oracle.xml.scalable.InfosetReader oracle.xml.parser.v2.XMLDocument.getInfosetReader()
at oracle.xml.parser.v2.XMLDocument
at public oracle.xml.parser.v2.XMLDocument testws.jaxws.TestXML.arg0
at testws.jaxws.TestXML

I reported the issue to Oracle forum and found that JAXB could not marshal these classes and hence Jdeveloper pops this error. So currently either you can use classes that have default data bindings in JAXB or probably need to write your own binding file or as a workaround you can either use Object type.

Well if there are any other methods that are causing this issue and you do not intend to expose them as service (which wasn't my case), annotate these method by @WebMethod(exclude=true). Currently JDeveloper doesn't annotates by default but hopefully this functionality will be added in future (Bug 9749573 is already logged for this issue)

How to configure CSS editor in Jdeveloper for ADF Faces RC?

Please do follow below steps to configure JDeveloper for CSS:
1. Got to Tools-> Preferences -> CSS Editor
2. Set ‘Support CSS Level’ to CSS Level 3
3. Check ADF Faces Extension checkbox.