cancel
Showing results for 
Search instead for 
Did you mean: 

Enterprise Java Bean as Model

Former Member
0 Kudos

Hi,

we want to use EJB's as models in Web Dynpro. Because there is no possibility at the moment to include them as models directly, we decided to use Java Beans instead. That means, a Java Bean encapsulates a method of an EJB.

We decided not to expose the ejb as a webservice and import that as a model because performance is a big issue.

My question is: is this way (calling an ejb via a Java Bean) an "officially" supported workaround?

And if so: how has the Java Bean to be implemented? Namely we aren't able at the moment to add any jars to the Java Bean (e.g. jars to call the ejb). When we do this, the Java Bean is not recognized any more in web dynpro.

Any help to this topic is appreciated.

Greetings.

Achim

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi everybody,

thanks to all for the very helpful posts.

We finally managed to call the ejb from our JavaBean in WebDynpro. The main obstacle at the end was the fact, that the properties of the JavaBean were complex types and we included the corresponding classes in the JavaBean archive as another JAR-file. We finally discovered that this was the reason which prevented us to import the JavaBean in WebDynpro.

After we extracted the JAR-file of the complex classes in the JavaBean the import in WebDynpro and the call to the EJB worked as expected.

Greetings.

Achim

Former Member
0 Kudos

I think this works for a File Project. But if your Web Dynpro,EJB and Java bean Project are DC (Development component Projects), then how do we refer these projects. I am unable to refer the Java Bean DC Project in my webdynpro.. Any help will be highly appreciated.

Former Member
0 Kudos

hi,

if u created ur EJB u can access it in webdynpro using the following code.

try{

InitialContext ic = new InitialContext();

Object obj = ic.lookup("localejbs/<Project name>/<Bean name>");

<UrlEjbLocalHome object> home = (UrlEjbLocalHome)PortableRemoteObject.narrow(obj,UrlEjbLocalHome.class);

UrlEjbLocal ejb = home.create();

<then create a context attribute of java native type of URLEJBBEAN type and set is as follows , here bean1 is that context attribute>

wdContext.currentContextElement().setBean1(ejb);

// wdComponentAPI.getMessageManager().reportSuccess("before connection");

<I have connect as my method in my bean that i'm accessing in this below line>

j = ejb.connect();

<now u can continue ur code >

<

a = ejb.getNodeListForAdd();

num = ejb.getNoOfNodes();

}

else

{

// wdComponentAPI.getMessageManager().reportSuccess("not connected");

}

}

catch(Ex)

{}

hope this helps u.

Regards,

Sirisha

Former Member
0 Kudos

Hi Achim,

Your solution of encapsulating EJB methods in a JavaBean and importing the JavaBean into Web Dynpro is a great solution which I have personaly used in the past.

I would not call it a work around. It is a J2EE design pattern, where the JavaBean acts as a facade to the EJB.

You will need of course to implement the EJB lookup code in the JavaBean or one of it's helper classes.

You need to pack the JavaBean code and it's related classes into a JAR, and import the JAR via the Java Bean import model in Web Dynpro.

G-Luck,

Itai

Former Member
0 Kudos

Hi Itai,

how exactly did you pack the JavaBean code and it's related classes (e.g. ejb-access) into the JavaBean jar? When we added a JAR-file which contained the related classes to the JavaBean jar, we could import the JavaBean as a model but got a 'ClassNotFoundException' for the related classes.

When we packed the related classes directly into the JavaBean jar (without encapsulating them into another jar), we weren't able to import the JavaBean jar as a bean model any more.

Former Member
0 Kudos

It seems that exact pattern name is Business Delegate

http://java.sun.com/blueprints/corej2eepatterns/Patterns/BusinessDelegate.html

VS

Former Member
0 Kudos

Hi Achim,

I'm adding a link to a zip files that includes a Web Dynpro project, an EJB project file and a Java Model Bean project. I created these projects to demonstrate how the import functionality works. I'm sure this is not the only way to do it, but this worked from me.

You can DL the files from here:

http://sapmats-de.sap-ag.de/download/download.cgi?id=3LXQLCRBVBXHBBT5FLHY8F99JQQEYS6VDHXDR0WJV514CQ1...

Itai

Former Member
0 Kudos

Hi,

For my knowledge you can't achieve this using the java bean importer.

Java Bean importer will take simple bean as input.

regards, Anilkumar