cancel
Showing results for 
Search instead for 
Did you mean: 

Getting Data from EJB to WebDynpro

Former Member
0 Kudos

Hello to you all,

I did make a working EJB, means I get Access to my external DB

and data has already been displayed in a .jsp.

Now my Question is, how to bring the Data to WebDynpro?

Did write a CommandBean with Variables like ResultSet, Array[], More Dimensional

Array[][]

But WebDynpro doesn't support any of these Types.

Means I've tried:

-right click- on Models and then

Create Model importing a .jar file I made from the CommandBean.

Should I make the DB-Accessing and Connection IN the WebDynpro Component Controller??? I don't think so...

Please give me some hints!

Thanks a lot!

Bernd

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Bernd,

we have a little example of this in our NWDI tutorial: https://sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/600cb8d1-a8be-2910-a0b1-f13d32d42690

Just unpack the zip and open index.html (not overview.html )

kind regards

Stefanie

Former Member
0 Kudos

Hello to all you,

thx a lot for your great replies.

I finally solved the Problem in two ways.

In both i used DAO and DTO for Database Connectivity and Implementation.

Then I

1. Deployed a WebService Accessing Data in the WebDynpro

And

2. Did make a Business Delegate Layer to map Data.

Here my hint:

I prefer Using the Business Delegate Pattern because of Security Reasons.

No 3rd can Acces my Data because of Referring to the JNDI, which is (in most cases)

my secret

Or make sure, that noone can Access your Data by using a WebService,

he only has to know the URL. Herefore use one of the Security Mechanism

provided by WebServices.

Thats it!

Greetz

Bernd

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Bernd,

Do the following steps and get the data from EJB to webDynpro

1) Open the J2EE perspective

2) Create an EJB Module project

3) Right click on ejbModule, create a new EJB (select your EJB type)

4) While creating the ejb itself, you can add business methods by clicking ‘Next’ in the UI. Another option is after creating the ejb, write the method in the bean, then select the method from ejb-jar.xml -> <bean name> ->method. Right click and select ‘propogate to local & remote’.

5) Double click on ejb-j2ee-engine.xml. select your bean and specify a Jndi name for eg: “MyJndi”.

6) Right click on the EJB project and add ‘classes12.zip’ file (provided by Oracle) to it’s build path. (under libraries tab). Also check the same file under ‘Order & Export’.

7) Create an Enterprise Application project.

😎 Right click on the EJB module project and select add to EAR project, then select the created EAR project.

9) Right click on the EJB project, select ‘Build EJB Archive’

10) Right click on the EAR project, select ‘Build Application Archive’

11) Open the WebDynpro perspective, open a new project, right click on the project ->properties. Do the following configurations :-

• Java Build path - select the EJB project from ‘projects’ , check the selected project under ‘Order & Export’

• Project references – select the EAR project

• WebDynpro references – select ‘sharing references’ tab, click add & make an entry as : <vendor>/<EAR project name without .ear extension>

You can find the vendor name under ‘application-j2ee-engine.xml’ file of the EAR project. By default it is ‘sap.com’. So if my EAR project’s name is ABC, my entry would look like ‘sap.com/ABC’

12) Now the configurations are over and the EJB can be invoked by writing the client code inside the webdynpro component. Like:

Context initialContext = new InitialContext();

InitialContext ctx = new InitialContext();

String lookupString ="sap.com/ABC’";

Object obj = ctx.lookup(lookupString);

GradeAnalysisQueryDataHome ejbHome =( GradeAnalysisQueryDataHome) javax.rmi.PortableRemoteObject.narrow(obj,GradeAnalysisQueryDataHome.class);

GradeAnalysisQueryData simpleEJB = ejbHome.create();

where

---ABC means the name of the ear file under comes up in the Enterprise Application

---GradeAnalysisQueryDataHome means the name of the home interface

there is no need to go Bean model...the above steps are enough..

if u using oracle database import into the class12.jar file..

thats all..

Former Member
0 Kudos

Hi Bernd

Instead of Array[] or ResultSet, try making your EJB return Collections of DTOs (<a href="http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html">Data Transfer Object</a>). The DTO can then be made part of your model, and you'll be able to import model and bind it to context.

You didn't describe in detail your EJB layer, but I assume you have a Stateless Session Bean as a front end that delegates to Entity Bean for DB access. If not, you should (<a href="http://java.sun.com/blueprints/corej2eepatterns/Patterns/SessionFacade.html">Session Facade Pattern</a>). Using a <a href="http://java.sun.com/blueprints/corej2eepatterns/Patterns/BusinessDelegate.html">Business Delegate</a> is also considered good design. In that situation, your Command Bean would call methods on your Business Delegate, which in turn delegates to the Session Bean. The Session Bean can then call Entity Beans for DB access - or you can code JDBC right in the Session Bean if you prefer... but DON'T code DB logic in Web Dynpro !! That's a big no-no.

Former Member
0 Kudos

thx a lot Department NetWeaver for those great hints!

but i see that in those transfer objects i have to implement a variable

for each field i get in a query.

isn't there any better and more convenient chance to bring data to WD?

you have to know, that i have to write a application using round about

90 queries on the most different tables, very strang db-design...

which is not changable at the moment...

greetz

bernd

Former Member
0 Kudos

If each of these 90 queries are independant of one another and can be manipulated separately in your application, then I don't see alternative to creating 90 DTOs. That's the DTO's role : to move data between tiers and processes.

If, on the other hand, you have 90 different queries due to questionable DB design, but you have only a few places in your WDP application where you actually invoke a call to the back-end, then you could structure your DTOs to represent data from more than one query. Example: you have one business process called getSomeData() that you invoke on the Business Delegate. It, in turn could invoke getSomeData() on the Session Bean. The Session Bean could then invoke possible several calls to the Entity Bean/DB layer, each call possibly dealing with more than one DB table. But all the data returned by your resultsets could in principle be accumulated in some big DTO that would then be returned to the calling WDP program in one shot.

The guiding principle is that a DTO represents a packet of data that can be sent across the wire - between WDP application tier and back-end EJB tier. But nothing prevents you from filling your DTO in bits and pieces on the DB side - as required by your particular DB implementation. Does this make sense to you ?

Former Member
0 Kudos

yes,

know now what you mean.

i will try using DTO, btw. Business Delegate.

look how it works and will write back to this thread soon!

thx so far!

Former Member
0 Kudos

hi,

i am trying to solve my problem, but got several questions now.

can anyone of you give me an example using dto, business delegate?

would be nice.

thx a lot!

Former Member
0 Kudos

Great reply ..I always wanted to code professionally . I am a dot net programmer, now slowly learning ejb for dynpro . I am looking solution for my problem with session facade pattern . I have a data in sql 2000 table , which i want to capture with a method in ejb . I want to use the output of this EJB method as model in webdynpro and map context . I am planing to make 1)Entity bean(CMP) with jdbc connection to sql , I will fetch data in its getVendordatamethod() which returns an array similarly I plan to put few more methods here 2)I will create a stateless session bean ...But I don't know what to do here apart from instantiating cmp bean and again return a collection 3)I will create a sessionfacade bean ...But what to do here ?

4) I will call this sessionfacadebean in webdynpro component controller and in code pass parameter to these methods . The returned collection object will be bound to a view-tree . I am totally confused ..Can u please give a solution to this ? . The link provided by you for sample code is not working . I also want to use business delegate pattern

I am awaiting for your reply . I am also looking for great example links

Former Member
0 Kudos

Hi Narasimha,

Were you able to do this?

If so, how did you do it? Did you also make use of a javabeans model?

If you have a document on how you did this, that would be great!

I need to get data from MS SQL via EJB.

That EJB has to be used in webdynpro and somehow the fetched data has to be shown in a table. I know this can be done via context, but isn't there a need for a model based on EJB?

I just don't understand what I can do in EJB to create a model since I only need to fetch data from SQL and show it on the screen...

Kind regards

Greg_Austin
Active Participant
0 Kudos

Web Dynpro doesn't have those types in the context, but you can most certainly use them in web dynpro code. You can do some manipulation to get from those data types to types you can put in context if that is what you are trying to do.

Former Member
0 Kudos

yes,

i want to get a dynamic ResultSet from the EJB to my WebDynpro.

But more Complex Types don't work too...

any suggestions?