Tuesday, December 27, 2011

Using Bean Validation together with ExtVal in JPA and JSF

With the release of WebLogic 12c we can finally try out the native support for Bean Validation ( JSR-303) in JPA & JSF. With JSR-303 we can use this validation framework on the back-end side ( EJB Session Bean ) and on the managed bean of the JSF Web applications, so one framework which can do it all. It will save us a lot of time in making business rules and no need for validators on our JSF UI Components.
To make this even better I will combine this with Apache MyFaces Extensions Validator. This framework can be used with JSF ( there is a generic library and a special one for Trinidad ) and its supports the Bean Validation. ExtVal also has some extra features.

  • Type-safe group validation
  • Model validation
  • Severity aware validation
  • Client-side validation
  • Sorted violation messages
  • Dependency injection support for constraint validators
  • Mapped constraint source (e.g. for using DTO's with BV)
  • Support of @Valid

In this blog I won't give you all the possible validations options you can have in the Bean Validation or in ExtVal framework but I will try to give you a jumpstart, how to setup this up and get everything working.

Before I start I got this working with WebLogic 12c and use OEPE 12c as my IDE. For the JSF part I use Apache MyFaces Trinidad 2.0.0 which support JSF 2.0.

Let's start with the JPA part.

Here I have created a department entity which is based on the department table of the HR demo schema in the Oracle database.

On the departmentName attribute I added some validation annotations like NotNull , Size and Pattern.

On the Pattern annotation I added a custom resource bundle message ( use {} ), I only do it for pattern annotation because Size or NotNull will have it's own default message in JSF.

Bean validation is the default now so we would see the Eclipselink error anymore. So when we try to persist an entity which violates these annotations we get an error like this.

With a javax.validation.ConstraintViolationException on a prePersist callback event. This error won't give you a lot of information about the error.

You got the option to disable the Bean Validation in Eclipselink by setting the validation-mode to NONE. This way you will get the constraint error.

Like this.

So how we can retrieve these validations errors. For example I can do this on the client side before I invoke the EJB Session bean or do it inside the Session Facade methods.

We need to use the resource annotation to retrieve the Validator.
(@Resource Validator validator; )
In the department persist we can pass on the department entity to the validatior.
Set<ConstraintViolation<Department>> violations = validator.validate(department);
And loop through the violations with this as result.

error size: 2
invalid value for: 'departmentName': Name must between 2 and 30 characters
invalid value for: 'departmentName': {departmentNameValidation}

Now we can go the JSF part.
Here I do the same but then from a managed bean which is called from a commandButton.

I changed the violations to Faces Messages and skip the persist part.

This is all standard Bean Validation stuff so let's check out the ExtVal part.

I added the following libraries to the lib folder of the WEB-INF

The jsr303-tck and the validation-api jars are from Hibernate Validator and the rest is from MyFaces ExtVal. Where I remove the myfaces-extval-generic-support-2.0.5.jar because I could use the trinidad one.

To test the validation I made a simple JSF Trinidad page where you can see there are no validator or convertors defined.

In the Trinidad table I show all the departments and change for example the department Name to 1 char which violates the Size annotation.

When I use invalid characters for the department Name then I get the resource bundle message.

To make this resourcebundle work I need to set a context parameter in the web.xml which points to our own resourcebundle.


The last part is to show you the ExtVal part. I used this managed bean which are used in the JSF page.

departmentName use the Bean Validation framework and departmentLocation use the ExtVal framework.
With this as result.

When you want to know more about ExtVal or Bean Validation you definitely should read this example chapter of Bart Kummel's Book about MyFaces Development.

Here is the example project on github.

Sunday, December 18, 2011

WebLogic SCA with WebLogic 12c and OEPE 12.1

Fusion Middleware Software like OSB or SOA Suite is not yet available on WebLogic 12c but this does not mean you can't develop SCA Applications. With the help of the Oracle Enterprise for Eclipse 12.1.1 ( OEPE ) we can build WebLogic SCA application and deploy it on WebLogic 12c. This allows you to write Java applications using POJOs and, through different protocols, expose components as SCA services and access other components via references. You do this using SCA semantics configured in a Spring application context. In SCA terms, a WebLogic Spring SCA application is a collection of POJOs plus a Spring SCA context file that wires the classes together with SCA services and references.

In this blogpost I will show you all the steps so you can try it yourself.

Before we start, we need to install WebLogic 12c, configure a new domain and startup the AdminServer.
The first step is to install the WebLogic SCA shared library and target it to the AdminServer.

Log in to the WebLogic Console and go to deployments windows.
Install this war  located at wlserver_12. 1\common\deployable-libraries\weblogic-sca-1.1.war as a shared library and target it to the AdminServer.

Next step is to download OEPE 12.1.1, extract it and create a new workspace.

In this workspace we need to create a new Dynamic Web Project.
Use wls 12 as Target runtime and also create an Ear project which will include the war.

Open the project options of your Dynamic Web Project and go to Project Facets.
Here we need to enable Oracle WebLogic SCA and Spring.
Click on Further configuration required.

Next step is to download the Spring library. Click on the download button and select Spring Framework 2.5.6 of Oracle.

Click on Next.

We need to add the WebLogic SCA Shared Library, this will be added to the weblogic.xml deployment descriptor of your Web Project.

You can open the weblogic.xml file of your Web project and in the Shared Libraries you should see the reference.

When you are in the Web Perspective then you can open the spring-context.xml in the beans section of the Spring Elements.

Or in the java perspective this is located in the jsca folder of the META-INF folder.

In the Spring-context.xml we will add some spring beans which have an EJB & Web Service SCA service and we also add some SCA references.

In this demo I will start with a SCA service with has a ws binding , this service has a target to a spring bean. This spring has a property to a SCA reference which an EJB binding.
The SCA reference calls a SCA Service which off course also has an EJB binding. The service target the next spring bean which the calls the last spring bean.

We start with the last spring bean and end with the first SCA service.
This the LoggerOutput class which just do a system out.
Because we want to expose the next spring bean as a SCA service we need to have an interface which we can use in the SCA service.
And now the implementation which calls the last spring bean LoggerOutput
Now we have everything to make our first SCA application. This is how the spring-context will look like.
This SCA service will be invoked in the second part of this blogpost where we will call this EJB from a web service. We can use the same ILoggerComponent interface for the SCA Service ( this time a web service ) and the SCA reference will call the already created EJB SCA service. We only need a new spring bean which pass on the message to the EJB. For this I use this LoggerPassThrough class.
Here is the total spring-context.xml
We are ready to deploy it and do a test run. Select your EAR project, right click and do run on Server.
Provide the details of your WebLogic 12c domain.

You can use soapUI to invoke the SCA Web Service http://localhost:7001/WebLogicSCA/LoggerService_Uri?WSDL
or invoke the SCA EJB Service
ILoggerComponent logEJB = (ILoggerComponent)context.lookup("LoggerService_EJB30_JNDI");

WebLogic also has an extension for WebLogic SCA , in the Console , go to the Preferences , Extensions and enable weblogic-sca-console.  You need to restart your WebLogic Server.

After this you can click on your SCA deployment and see your SCA Services and references.

Download the code at github

Monday, November 21, 2011


When you use an external web service in combination with a BPEL service component in an Oracle SOA Suite 11g composite and you follow this great AIA blog about Best Practices for Decoupling Services and Avoiding Invalid Composites at Server Startup then you can get this __OAUX_GENXSD_.TOP.XSD error in

  • JDeveloper, when you build the composite.
  • On the SOA Suite when the service is invoked for the second time, probably on your test or acceptance environment. 
Before we start with the possible fixes, first why do you get this error. 

You can only get this error when you use BPEL in your composite. With the mediator service component I don't get this error.

In my test composite I have a simple OSB proxy and use this as a reference. So I provide the WSDL url to the WS adapter and enabled the option to download the WSDL to your project.   

Because I don't want any deployment problems ( invalid composites at deployment time or at a soa server reboot when the OSB proxy is down ). I downloaded the XSDs of the WSDL, fixed the WSDL imports. Now we can put the WSDL and the XSDs in our project folder or add them to a central place like the MDS. 

When we take a look at the reference part in the composite.xml you will see the following.
The endpoint is loaded from the Customer.wsdl ( location attribute of the element ) and uses the port attribute to find the endpoint in the Customer.wsdl.

Here is the wsdl with the endpoint.

This works great in development ( cause you don't need to change anything)  but when you have to deploy to test or acceptance you will generate a config plan where you override the location attribute of the (reference) with the Test OSB Proxy WSDL url, so it will use that endpoint for test or acceptance.

On the SOA Suite you can invoke this service once and after that you can get this __OAUX_GENXSD_.TOP.XSD error. Somehow the second time the SOA Suite will retrieve the test OSB Proxy WSDL and it's XSDs from the cache and it compares it with the local XSDs of your project or MDS. When there is a difference in one of the XSDs you will get this error ( can be something minor like an element annotation ). 
This can also happen in the JDeveloper SOA Composite builder when you load the same XSDs local and remote. 

So the solution is to keep the XML schemas in sync ( remote and local ) but this is almost impossible or you need to build everything with Maven or ANT and always replace the XSDs in every project. This also requires a lot of unit testing.

Even then you probably don't have much influence on remote services. 

So the best solution is to avoid the loading of remote WSDL. You only need to update the endpoint for the Test or acceptance environment, not to load the whole WSDL. So don't try to replace the location attribute of the element in the composite.xml but try to update the endpoint in the WSDL located in your project or in the MDS.   

And if you use contract first Java (EJB) Web Services in Oracle Suite then you should always use the WSDL and the XSDs in your Java Web Services else you will get different schema imports then the original WSDL & XSDs.

I tested this with the Patch Set 3 version of SOA Suite 11g. 

Tuesday, November 8, 2011

Changing a navigation model on a page in WebCenter

WebCenter has a default navigation model (menu) which is located in the navigations folder and is defined as portal preference in the adf-config.xml file. But this menu is used in every page of the portal. I want to change this, so when you are not authenticated you will see the normal website links. But when you go to the internal page the menu will be switched to the application navigation model.
Special thanks for Maiko Rocha of the WebCenter A-Team for helping me solving this requirement.

First I create a new jspx page based on the global template called Internal.jspx and add a navigation reference to this page in the default-navigation-model.xml.

Now we can create a navigation model which will be used in the internal page. This menu has a link to the home page so the user can go back to the default menu.

Open the global template called pageTemplate_globe.jspx and go the menu part.  Here we will change the default navigation model.

#{navigationContext.defaultNavigationModel.listModel['startNode=/, includeStartNode=false']}

#{navigationContext.navigationModel[ ]                                  .listModel['startNode=/, includeStartNode=false']}

Where menuSwitcher is a request bean.

To determine what navigation model I need to use I will check the current page and return the right navigation reference.

The request bean

You can also use EL instead of a request bean.

<af:forEach var="node" varStatus="vs"
          controllerContext.currentViewPort.viewId eq '/oracle/webcenter/portalapp/pages/Internal.jspx' ? 
             '/oracle/webcenter/portalapp/navigations/navigationModelInternal.xml'  : 
   ].listModel['startNode=/, includeStartNode=false']}">

Here some pictures of the home page

After being authenticated, some extra menu links appears

And at last, the internal page with the new navigation model.

Friday, October 28, 2011

Playing with ADF Task Flows in OEPE

Oracle released the Oracle Enterprise Pack for Eclipse 11g R1 (, New October 2011 ) which supports ADF Rich Faces with ADF Task Flow development. To see all the new features you can go this page for all the ADF or Oracle Cloud feature list.

In this blogpost I will show you some steps how to make your own ADF Web application in OEPE.

Before you can start you should know that the ADF application in OEPE uses JPA as model ( eclipselink), ADF BC can be used but only on runtime and you should already have WebLogic PS3 or higher installed ( together the ADF runtime option).

This OEPE release does not have ADF wizard for ADF BC or for ADF Datacontrols but the support for ADF Task Flows is a big step forward.

Let's start.
Start with a new Oracle ADF Application

Add a new WebLogic runtime, define your WebLogic home and run the domain wizard to create a new ADF enabled domain. Make sure you add the JRF option to the domain.

You should use JPA as a model project with Oracle ADF 11g JPA Project as the configuration.

This will create 2 projects, Model and AdfGuiWeb and 1 ear deployment called AdfGui.

Create a JSP File which will be our start page.

Select the location for the JSPX page

Choose for ADF Rich Faces Page , Basic xhtml

Open the adfc-config.xml and drag the jspx page to the diagram, this will create a new view.

Create a new ADF Fragment Task Flow which will hold the department fragments

Select the location.

The fragment option should be enabled.

Create a new JSP page which will be our fragment page, called department.jsff

Now choose ADF Rich Faces Page Fragment

Open the departments TF and drag this fragment to this Bounded Task Flow.

Now we can go the model project and delete the model project. OEPE does not support ADF Datacontrol generation, so we will skip this for the demo.

Now you are able to run the JSPX page. Select the startView.jspx and right click Run As -> Run on server.

After a successful run we can add an outputtext to the page and the fragment

Now drag the department Task Flow to the jspx start page and select Region. This will create the ADF binding pagedef file.

We can open the pagedef file and add your own bindings.

Or open the Data Palette window which shows you the available bindings

At last open the project options to enable the shared libraries

Now you can run the start page with the Bounded Task Flow fragment.

As an extra you can also add some data to the page by fixing the Model project.
First add a database connection to the model project
Add JPA entitities from tables
Add a connection to the persistence.xml

Add Data Model Components to the Model project. This will create a managed bean for the JSF page and an EJB Session bean for the entities

EJB Session Bean

JSF bean

the managed bean code

The Data Pallette, drag and drop the FindAll method to the fragment page

And the result.