Tuesday, February 11, 2014

LOV (List of Values) using EJBs

Following a request, I would like in this post to demonstrate how to use EJBs to build your business services and how to build a simple form with a list-of-value component (using the selectOneChoice component).

 I created an application using the "Fusion Web Application (ADF)" template, i initialized my model project by creating a database connection to the HR schema and created two EJB entities, one for the Employees table and one for the Departments table.


I created a session bean using the default settings (with all methods from both entities being selected) and generated a data control from the session bean by just right-clicking on the session bean and selecting from the context menu "Create Data Control".


I created a page (employees.jspx) and dropped the employeesFindAll collection on the page as a form (for demo purposes i am just using three attributes: EmployeeId, FirstName and LastName). The initial requirement was instead of displaying the department id to have a drop down displaying the department name.

When you created the EJB entities from table, ADF interrogated the database catalog and identified the relationship between the two tables, thus injecting it into the Employees EJB.


To add the department name as a list-of-value just drag and drop onto your page the nested departments collection as an ADF Select One Choice component.

Run the employees page and you will see that ADF will synchronize the department list as you navigate between different employees.


Download sample application: LOVsUsingEJBs

Wednesday, February 5, 2014

Working with the selectManyCheckbox component

I recently came across a simple, yet not so straightforward use case as it seems for many ADF developers on the JDeveloper & ADF forum so I decided to blog about it.

The requirement was to use the selectManyCheckbox component and to save the selection in the database in a varchar2 column of type.

So I created a custom table in the HR schema, MY_EMPLOYEES with 3 columns; ID (number), NAME (varchar2) and  DEPARTMENTS (varchar2).


I then created the basic ADFBC objects (an entity MyEmployees based on the MY_EMPLOYEES table, a view MyEmployeesView based on the MyEmployees entity and an application module AppModule that has the MyEmployeesView selected in the data model).


Moving on the ViewController project, i created a page (employees) where i dragged the MyEmployeesView view object as an ADF Form (JDeveloper created automatically for me the 3 attributes Id, Name and Departments).

From the component pallet i added  a selectManyCheckbox component, accepting the default settings (just changed the label to Departments) and a button component (which i called Save).


In the page bindings I just added the Commit operation as an action (so that i can invoke it from the Save button).

All the logic is implemented in a managed bean with scope set to pageFlowScope. Both the selectManyCheckbox and selectItems values are set from the bean. 



Same goes with committing the data (selected departments). This is handled via a bean method.

  
You can test the application by running the employees.jspx page. Select one or more departments and click save. The selection array is stored in the varchar database column.


On loading the page the bean will convert the string back into an array and assign it to the selectManyCheckbox component.

Download Sample Application - WorkingWithTheSelectManyCheckboxComponent

Tuesday, February 4, 2014

Oracle Fusion Middleware Partner Community Forum 2014

Hi everyone,

This year Oracle is organizing its Oracle Fusion Middleware Partner Community Forum in Malta. The event is going to be held on February 18th and 19th 2014 with hands-on training on February 20th & 21st 2014.

The event is a great opportunity to learn about:
  • SOA Suite 12c & Cloud integration
  • BPM Suite 12c & Adaptive Case Management 12c
  • Internet of Things & mobile strategy & fast data
  • WebLogic 12c the foundation of Oracle Fusion Middleware
Oracle will be running the following hands-on bootcamps:
  • Internet of Things (IoT) hands-on Bootcamp
    • Trainer: Harish Gaur, Director Product Management at Oracle
  • Coherence 12c hands-on Bootcamp
    • Trainer: Maciej Gruszka, Senior Principal Product Manager at Oracle
  •     Mobile Platform Cookbook Concepts and Practices Workshop
    • Trainer: Frank Nimphius, Principal Product Manager at Oracle
  • Adaptive Case Management hands-on Bootcamp
    • Trainer: Niall Commiskey, Technology Architect
Don't miss this unique experience.

See you all in Malta!

Wednesday, December 18, 2013

How to Create Your First EJB Bean

In this post i would like to highlight the importance of EJBs into the SOA world and demonstrate how to create a simple EJB (with a couple of advanced posts on EJBs following in the very near future).

So let' start with the definition of what an EJB is.

 Enterprise JavaBeans (EJB) is a Java EE server-side component architecture for modular construction of enterprise applications. Due to it's numerous advantages (portability, productivity, integration with the J2EE platform, scalability, etc.) it remains a precious weapon into any developer's hands. Especially in large, complex, enterprise SOA implementations.

So let's see how you can jump start yourself into the EJB world.

I've very quickly created an application ("HelloWorldEJBApp") with a single project ("HelloWorldEJB").


There are three types of beans that you can create:

  • Stateless Session Beans: As it's name denotes, this bean does not store session or client state information between invocations.
  • Stateful Session Beans: Stateful Session Beans maintain state information between the bean and a specific client.
  • Entity Beans: Represent a set of persistent data and provide methods for maintaining and reading these data.
Stateless Session Beans can support multiple clients, offering better scalability, therefore i will be using this type of bean in my example.


Create a new Session Bean (right-clicking on the project and from the "All Technologies" tab select "EJB" from the "Business Tier" category. Select "Session Bean" from the items).


On step 1 of the "Create Session Bean" wizard, make sure you select the latest EJB version which is 3.0.

On step 2 provide an EJB name (in my example it's "HelloWorldSessionEJB"). In this step you have additional options such as the session type (in our case it's a stateless session type), transaction type (whether the bean will be managed by the Weblogic Server EJB container or by the EJB itself; in our case it will be set to "Container"), whether to implement the TimedObject interface for delivering timer exception notifications, customizing the mapped name (i will leave it as is. In my case it's "HelloWorldEJBApp-HelloWorldEJB-HelloWorldSessionEJB") and whether to generate session facade methods (it's not applicable in our case since we are not using any persistent unit).


On step 3 specify the bean class name and path and on step 4 select whether you would like to implement a remote and/or local interface. If you will be deploying and using the EJB from the same tier then just select the local interface, otherwise if you will be deploying and accessing the EJB remotely then select the remote interface.In this example i will be demonstrating how to use the remote interface (since it makes more sense in a SOA environment).



Click finish. You should have 3 files created; "HelloWorldSessionEJBLocal.java" which is the local interface created for your bean, "HelloWorldSessionEJBBean.java" which is the bean implementation class and "weblogic-ejb-jar.xml", a Weblogic Server specific EJB deployment descriptor file.

I will create a simple method in the EJB implementation class as follows:

    public String sayHello(String name){
        return "Hello " + name;   
    }


Make sure you register this new method in the remote interface








and add the "WebLogic 10.3 Thin-Client" jar in the project's "Libraries and Classpath".


To test your EJB you will first need to generate a sample java client and secondly you need to deploy the EJB to your JDeveloper's integrated Weblogic Server.

To generate a sample client just right click the EJB implementation class and select from the context menu "New Sample Java Client ...".


Update the generated client java class as follows to call the sayHello EJB method:

            HelloWorldSessionEJBBeanRemote bean = (HelloWorldSessionEJBBeanRemote)context.lookup("HelloWorldEJBApp-HelloWorldEJB-HelloWorldSessionEJBBean#aantoniou.HelloWorldSessionEJBBeanRemote");
            String response = bean.sayHello("Antonis");

System.out.println(response);

To deploy your EJB bean just right-click on the bean and select run. JDeveloper will automatically deploy the bean onto the integrated Weblogic Server.

Once the bean is deployed run the client class and you should see onto the console the hello message returned from the sayHello EJB method.

That's it. You have successfully created your first EJB bean.

In the following posts i will demonstrate how to pack the EJB into a jar file and use it from different applications and how to service enable your EJB.


Tuesday, October 15, 2013

Error occurred while attempting to retrieve message part parameters from a normalized message payload with elements

Hi folks,
I'm back!
Sorry, for being lost for a while but i am running a really interesting project for the last year, a project that combines the entire Oracle Fusion Middleware stack and which i plan to share my experience with you.
Just stumbled on a really simple error so i thought of blogging it.
In case you faced the error stated in the post title (Error occurred while attempting to retrieve message part parameters from a normalized message payload with elements") it's because you didn't specify a reply transformation in your router for one of your process calls.

Stay tuned for some really interesting integration posts!

Thursday, July 5, 2012

Multi-Select Dependent Drop-Down Lists

I was recently at a customer's site where I had an interesting requirement so I have decided to blog about it. The requirement was to build a master/detail drop-down list. The challenging part was that they wanted the master drop-down list to be a multi-select drop-down list and the detail drop-down list should populate its details based on the master’s selection.

Since ADF does not support master/detail lists for multiple selections i had to follow a different approach. I used the HR schema, with the Departments table as the master drop-down list and the Employees table as the child detail drop-down list. So i created default business component objects (entities and views) based on the Departments and Employees tables.

The trick here is on the detail view object that will serve as the dependent drop-down list. I have created a string bind variable to pass the selected department Ids as a comma separated string of department ids. As you may know, the View Object SQL Query, if used as such, will interpret the whole comma separated value as a single string and of course the query will fail. So to overcome this issue, i have changed the SQL Query using the regexp_substr regular expression function to split the comma separated string and return them as rows (special thanks to Arun).

Employees.DEPARTMENT_ID in (select regexp_substr(:DeptId,'[^,]+', 1, level) from dual connect by regexp_substr(:DeptId, '[^,]+', 1, level) is not null)

In the Application Module, make sure that you add the Departments view object and Employees view object as separate view objects and not dependent. The master/detail dependence will be implemented in a managed bean.

So, create a page and drag on the page the Departments view as a Select Many Choice component and the Employees view object as a Select One Choice component.Make sure that you set the AutoSubmit attribute of the Departments Select Many Choice component to true and in the PartialTriggers attribute of the Employees Select One Choice you have a reference to the Departments Select Many Choice component so that the employees can listen for changes in the departments component.

Go to  the page bindings and create an action binding to the ExecuteWithParams operation of the Employees view object.Your page definition should resemble as below.

The last thing that needs to be done is get the selected department ids, construct a comma separated list of department ids, pass it to the DeptId bind variable of the Employees view and execute the query so that the Employees Select One Choice component gets populated with all employees that belong to all the above selected departments. To do so, edit the ValueChangeListener of the Department Select Many Choice Component and add the following java code to the exposed value change listener method.

public void onDepartmentChange(ValueChangeEvent valueChangeEvent) {
    BindingContainer bc = BindingContext.getCurrent().getCurrentBindingsEntry();

    BindingContext bctx = BindingContext.getCurrent();
    BindingContainer bindings = bctx.getCurrentBindingsEntry();
    DCIteratorBinding departmentIterator = (DCIteratorBinding)bindings.get("DepartmentsVOIterator");

    String deptId = null;
    // retrieve selected departments
    if (this.getDepartmentId().getValue() != null) {
        try {
            Integer[] departmentIds = (Integer[])this.getDepartmentId().getValue();

            if (departmentIds.length != 0) {
                for (int x = 0; x < departmentIds.length; x++) {
                    int departmentId = departmentIds[x];
                    Row department = departmentIterator.getRowAtRangeIndex(departmentId);
                    System.out.println("Department Id Index: " + departmentId + " - Department Id: " +
                                       department.getAttribute("DepartmentId"));
                    if (x == 0) {
                        deptId = ((Number)department.getAttribute("DepartmentId")).toString();
                    } else {
                        deptId =
                                deptId + "," + (String)((Number)department.getAttribute("DepartmentId")).toString();
                    }
                }
            }
        } catch (ClassCastException e) {
        }
    }

    OperationBinding queryEmps = bc.getOperationBinding("ExecuteWithParams");
    Map queryEmpsMap = queryEmps.getParamsMap();
    queryEmpsMap.put("DeptId", deptId);
    queryEmps.execute();
}

As you can see, all employees belonging to the selected departments (Administration, Shipping and IT) are populated in the employees Select One component.

Download Sample Application - MultiSelectDependentComboBox

Friday, June 22, 2012

Virtual Developer Day: Oracle Fusion Development

Oracle is offering another FREE virtual event where you have the opportunity to learn the latest in Fusion Development, including:
  • Is Oracle ADF development faster and simpler than Forms, Apex or .NET?
  • Mobile Application Development with ADF Mobile
  • Oracle ADF development with Eclipse
  • Oracle WebCenter Portal and ADF Development
  • Building Process Centric Applications with ADF and BPM
  • Oracle Business Intelligence and ADF Integration
  • Live Q&A chats with Oracle technical staff 
 Don't miss this opportunity. Register now!