How to leverage JNDI in Web Dynpro for Java
h2. *Web Dynpro Enterprise Java Bean models are great but…* On each and every Java Web Dynpro tutorial we have been taught that the correct way to use Enterprise Java Bean 3.0 in Web dynpro applications is EJB model. while this is a simple and effective concept for integrating WDJ and EJBs, the most experienced developers might have noticed a few drawbacks: ** no polymorphism allowed ** need to reimport the model or modify the generated classes upon ejb interface change What we will see in this blog is how to leverage the native lookup features of SAP Java Application Server, namely Java Naming and Directory Interface (http://www.oracle.com/technetwork/java/jndi/index.html). While proposing new ideas we will not reinvent the wheel, i.e. existing useful features of WDJ will be nonetheless leveraged. We will be studying how this can be done in SAP NW CE 711, realizing a proof of concept Web Dynpro application which will invoke a stateless session EJB deployed locally to retrieve a list of employees. The same APIs can of course be used with later version of SAP Java AS. Previous versions support JNDI as well but with minor differences. The figure below illustrates the final result: h2. *Decoupling web tier and business logic* engine.jee5.facade (required for JEE libraries)Our WDJ application component controller will just feature an Employee context node with cardinality 0..n, based on model binding with Employee model (see figure below) The view controller will have its own Employee context node mapped to the Component Controller’s, see figure below. Our view will show a simple table bound to Employee context node, see figure below. We will call our application “JndiApp” I won’t go into greater detail as there are plenty of tutorials and guides on this subjects. Bear in mind that our context is empty and our application does nothing yet, we are going to integrate it with our business logic EJB shortly. h2. Meet SAP WAS JNDI console In order for our WDJ application to perform some business logic, we need to enable the WDJ component to retrieve the stateless session EJB we previously created. To do so we need the JNDI lookup string from SAP WAS JNDI console. This name+ +represents the unique id of the EJB you want to lookup from your WDJ component. Go to NWA in your application server: http://host:port/NWA (http://host:port/NWA) And then: type “JNDI” in the search box in the upper right part of the screen, you will get only one result, that’s it! After starting the JNDI console, select Object in the drop down field and enter *EmployeeManager* in the input field. Then click +search+. You should get only one entry. Click on the appropriate entry and in the lower part of the screen you will see a detailed view.